From 468435e1a02b9dc6979598261e1a4d161b21bdf2 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Mon, 2 Aug 2021 00:08:26 -0700 Subject: [PATCH] Fix nullpointer when contraptions stop --- .../render/ContraptionRenderManager.java | 9 ++++++++- .../render/FlwContraptionManager.java | 18 +++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java index 57d9fa089..8d94a681a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/ContraptionRenderManager.java @@ -50,13 +50,17 @@ public abstract class ContraptionRenderManager } public void beginFrame(BeginFrameEvent event) { - visible.clear(); renderInfos.int2ObjectEntrySet() .stream() .map(Map.Entry::getValue) .forEach(renderInfo -> renderInfo.beginFrame(event)); + collectVisible(); + } + + protected void collectVisible() { + visible.clear(); renderInfos.int2ObjectEntrySet() .stream() .map(Map.Entry::getValue) @@ -80,6 +84,9 @@ public abstract class ContraptionRenderManager renderInfos.clear(); } + /** + * Remove all render infos associated with dead/removed contraptions. + */ public void removeDeadRenderers() { renderInfos.values().removeIf(ContraptionRenderInfo::isDead); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java index 8bdb46d9f..3aff78682 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/render/FlwContraptionManager.java @@ -80,13 +80,17 @@ public class FlwContraptionManager extends ContraptionRenderManager { - if (renderer.isDead()) { - renderer.invalidate(); - return true; - } - return false; - }); + boolean removed = renderInfos.values() + .removeIf(renderer -> { + if (renderer.isDead()) { + renderer.invalidate(); + return true; + } + return false; + }); + + // we use visible in #tick() so we have to re-evaluate it if any were removed + if (removed) collectVisible(); } @Override