From e44cc6847cc24f7cbfb67a2952b431bc51bf7a1e Mon Sep 17 00:00:00 2001 From: makamys Date: Wed, 22 Jun 2022 05:57:01 +0200 Subject: Fix memory leak Meshes wouldn't get unloaded properly if they were never sent to the GPU, or if they are transparent. --- src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java | 5 ++++- src/main/java/makamys/neodymium/renderer/NeoRenderer.java | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src/main/java/makamys') diff --git a/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java index fb73362..3901a7a 100644 --- a/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java +++ b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java @@ -49,6 +49,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer { public boolean needsUpdate; boolean savedDrawnStatus; + private boolean insideUpdateRenderer; public List chunkMeshes; @@ -71,6 +72,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer { @Inject(method = "updateRenderer", at = @At(value = "HEAD")) private void preUpdateRenderer(CallbackInfo ci) { saveDrawnStatus(); + insideUpdateRenderer = true; if(Neodymium.isActive()) { if(needsUpdate) { @@ -88,6 +90,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer { @Inject(method = "updateRenderer", at = @At(value = "RETURN")) private void postUpdateRenderer(CallbackInfo ci) { notifyIfDrawnStatusChanged(); + insideUpdateRenderer = false; if(Neodymium.isActive()) { if(chunkMeshes != null) { @@ -99,7 +102,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer { @Inject(method = "postRenderBlocks", at = @At(value = "HEAD")) private void prePostRenderBlocks(int pass, EntityLivingBase entity, CallbackInfo ci) { - if(Neodymium.isActive() && !Config.disableChunkMeshes) { + if(insideUpdateRenderer && Neodymium.isActive() && !Config.disableChunkMeshes) { if(chunkMeshes != null) { chunkMeshes.add(ChunkMesh.fromTessellator(pass, WorldRenderer.class.cast(this), Tessellator.instance)); } diff --git a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java index 7bc582c..d55119f 100644 --- a/src/main/java/makamys/neodymium/renderer/NeoRenderer.java +++ b/src/main/java/makamys/neodymium/renderer/NeoRenderer.java @@ -537,6 +537,10 @@ public class NeoRenderer { lodChunk.isSectionVisible[y] = change == WorldRendererChange.VISIBLE; if(change == WorldRendererChange.DELETED) { removeMesh(lodChunk.chunkMeshes[y]); + if(lodChunk.chunkMeshes[y] != null) { + lodChunk.chunkMeshes[y].destroy(); + lodChunk.chunkMeshes[y] = null; + } } lodChunkChanged(lodChunk); } -- cgit