Make sure stale wrappers are not stored in the client level map.

This commit is contained in:
Acuadragon100
2026-05-03 17:35:36 +02:00
parent 5cb30ed7ce
commit 809990f766
@@ -144,6 +144,7 @@ public class DhClientServerWorld extends AbstractDhServerWorld<DhClientServerLev
// but note that the server side still has the level loaded. So, we don't want to unload the level,
// we just want to stop rendering it.
this.dhLevelByLevelWrapper.remove(wrapper).stopRenderer(); // Ignore resource warning. The level obj is referenced elsewhere.
wrapper.onUnload(); // We still want to unload the wrapper though.
}
ApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelUnloadEvent.class, new DhApiLevelUnloadEvent.EventParam(wrapper));
}
@@ -174,6 +175,13 @@ public class DhClientServerWorld extends AbstractDhServerWorld<DhClientServerLev
ApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelUnloadEvent.class, new DhApiLevelUnloadEvent.EventParam(serverLevelWrapper));
}
IClientLevelWrapper clientLevelWrapper = level.getClientLevelWrapper();
if (clientLevelWrapper != null)
{
clientLevelWrapper.onUnload();
ApiEventInjector.INSTANCE.fireAllEvents(DhApiLevelUnloadEvent.class, new DhApiLevelUnloadEvent.EventParam(clientLevelWrapper));
}
// close levels asynchronously to speed up
// shutdown on servers with a lot of levels
CompletableFuture<Void> closeFuture = new CompletableFuture<>();