From fe89e0024a551193db9b615b32bcf73464662d6f Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Sat, 27 Jul 2024 18:00:44 -0700 Subject: [PATCH] Courier transformed - SimpleQuadMesh holds a reference to its backing MemoryBlock so the cleaner doesn't drop it - Fixes issue where meshes suddenly start rendering garbage --- .../engine_room/flywheel/lib/model/SimpleQuadMesh.java | 10 +++++++--- .../flywheel/lib/model/baked/MeshHelper.java | 2 +- .../flywheel/lib/model/part/ModelPartConverter.java | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/SimpleQuadMesh.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/SimpleQuadMesh.java index e7ff25a5b..92e1e9372 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/SimpleQuadMesh.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/SimpleQuadMesh.java @@ -6,21 +6,25 @@ import org.joml.Vector4fc; import dev.engine_room.flywheel.api.vertex.MutableVertexList; import dev.engine_room.flywheel.api.vertex.VertexList; +import dev.engine_room.flywheel.lib.memory.MemoryBlock; public final class SimpleQuadMesh implements QuadMesh { private final VertexList vertexList; + // Unused but we need to hold on to a reference so the cleaner doesn't nuke us. + private final MemoryBlock data; private final Vector4f boundingSphere; @Nullable private final String descriptor; - public SimpleQuadMesh(VertexList vertexList, @Nullable String descriptor) { + public SimpleQuadMesh(VertexList vertexList, MemoryBlock data, @Nullable String descriptor) { this.vertexList = vertexList; + this.data = data; boundingSphere = ModelUtil.computeBoundingSphere(vertexList); this.descriptor = descriptor; } - public SimpleQuadMesh(VertexList vertexList) { - this(vertexList, null); + public SimpleQuadMesh(VertexList vertexList, MemoryBlock data) { + this(vertexList, data, null); } @Override diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshHelper.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshHelper.java index 257ac4f09..6adb15dac 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshHelper.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/baked/MeshHelper.java @@ -42,6 +42,6 @@ final class MeshHelper { vertexView.ptr(dstPtr); vertexView.vertexCount(vertexCount); - return new SimpleQuadMesh(vertexView, meshDescriptor); + return new SimpleQuadMesh(vertexView, dst, meshDescriptor); } } diff --git a/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/ModelPartConverter.java b/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/ModelPartConverter.java index 1e4a17d27..c03ba9ec7 100644 --- a/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/ModelPartConverter.java +++ b/common/src/lib/java/dev/engine_room/flywheel/lib/model/part/ModelPartConverter.java @@ -37,7 +37,7 @@ public final class ModelPartConverter { VertexView vertexView = new PosTexNormalVertexView(); vertexView.load(data); - return new SimpleQuadMesh(vertexView, "source=ModelPartConverter"); + return new SimpleQuadMesh(vertexView, data, "source=ModelPartConverter"); } public static Mesh convert(ModelLayerLocation layer, @Nullable TextureAtlasSprite sprite, String... childPath) {