From 2c2f34cb235f8959323505232d4e441233df0cbe Mon Sep 17 00:00:00 2001 From: makamys Date: Fri, 4 Jun 2021 22:21:18 +0200 Subject: Make WorldRenderer safer I got NPEs here, this should fix it --- src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java b/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java index 112c97c..2ec3365 100644 --- a/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java +++ b/src/main/java/makamys/lodmod/mixin/MixinWorldRenderer.java @@ -50,7 +50,7 @@ abstract class MixinWorldRenderer implements IWorldRenderer { @Shadow public boolean needsUpdate; - public List chunkMeshes = new ArrayList<>(); + public List chunkMeshes; @Redirect(method = "setPosition", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/Render;renderAABB(Lnet/minecraft/util/AxisAlignedBB;)V")) private void redirectRenderAABB(AxisAlignedBB p1) { @@ -72,7 +72,11 @@ abstract class MixinWorldRenderer implements IWorldRenderer { private void preUpdateRenderer(CallbackInfo ci) { if(LODMod.isActive()) { if(needsUpdate) { - chunkMeshes.clear(); + if(chunkMeshes != null) { + chunkMeshes.clear(); + } else { + chunkMeshes = new ArrayList<>(); + } } else { chunkMeshes = null; } @@ -92,7 +96,9 @@ abstract class MixinWorldRenderer implements IWorldRenderer { @Inject(method = "postRenderBlocks", at = @At(value = "HEAD")) private void prePostRenderBlocks(int pass, EntityLivingBase entity, CallbackInfo ci) { if(LODMod.isActive() && !LODMod.renderer.disableChunkMeshes) { - chunkMeshes.add(((ITessellator)Tessellator.instance).toChunkMesh(pass)); + if(chunkMeshes != null) { + chunkMeshes.add(((ITessellator)Tessellator.instance).toChunkMesh(pass)); + } } } -- cgit