From d256397cb8a7d4f46fbb2cf796eb4ae69b7511cc Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Wed, 14 Jul 2021 15:35:52 -0700 Subject: [PATCH] Fix crash on resource reload - Backend wasn't properly cleaning up its state - Sneaky error in WorldAttached --- src/main/java/com/jozufozu/flywheel/backend/Backend.java | 2 ++ .../flywheel/backend/instancing/InstancedRenderDispatcher.java | 3 +-- src/main/java/com/jozufozu/flywheel/util/WorldAttached.java | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/backend/Backend.java index 8c5da8088..325b5653d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backend.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backend.java @@ -60,7 +60,9 @@ public class Backend { void clearContexts() { SpecMetaRegistry.clear(); + programSpecRegistry.clear(); contexts.forEach(IShaderContext::delete); + contexts.clear(); materialRegistry.clear(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java index 5800b0f5a..6f85062d4 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java +++ b/src/main/java/com/jozufozu/flywheel/backend/instancing/InstancedRenderDispatcher.java @@ -102,8 +102,7 @@ public class InstancedRenderDispatcher { } public static void loadAllInWorld(ClientWorld world) { - materialManagers.get(world) - .delete(); + materialManagers.replace(world, MaterialManager::delete); InstanceManager tiles = tileInstanceManager.replace(world); world.loadedTileEntityList.forEach(tiles::add); diff --git a/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java b/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java index 4d4d944e9..a91acb0e8 100644 --- a/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java +++ b/src/main/java/com/jozufozu/flywheel/util/WorldAttached.java @@ -50,7 +50,8 @@ public class WorldAttached { public T replace(IWorld world, Consumer finalizer) { T remove = attached.remove(world); - finalizer.accept(remove); + if (remove != null) + finalizer.accept(remove); return get(world); }