From 0f4ebe14655787174a7b24c28b35bcbba212f82a Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Mon, 26 Jun 2023 19:25:53 -0700 Subject: [PATCH 1/2] Fix memory leaks --- .../java/com/jozufozu/flywheel/core/model/BlockModel.java | 8 ++++++++ .../java/com/jozufozu/flywheel/core/model/ModelUtil.java | 1 + 2 files changed, 9 insertions(+) diff --git a/src/main/java/com/jozufozu/flywheel/core/model/BlockModel.java b/src/main/java/com/jozufozu/flywheel/core/model/BlockModel.java index 61df69354..86b1817e2 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/BlockModel.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/BlockModel.java @@ -54,6 +54,10 @@ public class BlockModel implements Model { } public BlockModel(Pair pair, String name) { + this(pair, name, true); + } + + public BlockModel(Pair pair, String name, boolean releaseBuffer) { this.name = name; RenderedBuffer renderedBuffer = pair.first(); @@ -66,6 +70,10 @@ public class BlockModel implements Model { eboSupplier = () -> QuadConverter.getInstance() .quads2Tris(vertexCount() / 4); } + + if (releaseBuffer) { + renderedBuffer.release(); + } } @Override diff --git a/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java b/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java index 4b58ba1e5..fc6499ad5 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java @@ -66,6 +66,7 @@ public class ModelUtil { if (unshadedBuffer != null) { // FIXME: Unshaded indices ((BufferBuilderExtension) shadedBuilder).flywheel$appendBufferUnsafe(unshadedBuffer.vertexBuffer()); + unshadedBuffer.release(); } RenderedBuffer buffer = shadedBuilder.end(); return Pair.of(buffer, unshadedStartVertex); From 7105c3914cbfa39c4b1820fa97160fa43f12e709 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Mon, 3 Jul 2023 16:27:25 -0700 Subject: [PATCH 2/2] Impossible leaks --- src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java b/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java index 713375dcd..77cb2dd23 100644 --- a/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java +++ b/src/main/java/com/jozufozu/flywheel/core/model/ModelUtil.java @@ -68,7 +68,9 @@ public class ModelUtil { unshadedBuffer.release(); } RenderedBuffer buffer = shadedBuilder.end(); - return new ShadeSeparatedBufferedData.NativeImpl(buffer.vertexBuffer(), buffer.indexBuffer(), buffer.drawState(), unshadedStartVertex); + ShadeSeparatedBufferedData bufferedData = new ShadeSeparatedBufferedData.NativeImpl(buffer.vertexBuffer(), buffer.indexBuffer(), buffer.drawState(), unshadedStartVertex); + buffer.release(); + return bufferedData; } public static ShadeSeparatedBufferedData getBufferedData(Bufferable bufferable) {