Fix dynamic lights world client leaks (#1700)

This commit is contained in:
Alexdoru authored and GitHub committed 2026-04-26 10:01:46 -07:00
1 parent 445dc487b9
commit 00fc97a611
4 files changed
+43 -30

No files matched your search

@@ -180,6 +180,19 @@ public class DynamicLights {
this.lightSourcesLock.writeLock().unlock();
}
/**
* Removes all tracked light sources, to call when unloading the client world
*/
public void removeAllLightSources() {
this.lightSourcesLock.writeLock().lock();
this.dynamicLightSources.clear();
this.lightSourceCount = 0;
rebuildLightSourceArray();
this.lightSourcesLock.writeLock().unlock();
}
/**
* Removes light sources if the filter matches.
*
@@ -106,26 +106,6 @@ public final class ClientProxy extends CommonProxy {
blockError = new BlockError();
}
@SubscribeEvent
public void worldLoad(WorldEvent.Load event) {
if (GLStateManager.isRunningSplash()) {
GLStateManager.setRunningSplash(false);
LOGGER.info("World loaded - Enabling GLSM Cache");
}
if (AngelicaConfig.enableCeleritas) {
ChunkTaskRegistry.reset();
ChunkTaskRegistry.registerProvider(DefaultChunkTaskProvider.INSTANCE);
ChunkTaskRegistry.registerProvider(ThreadedChunkTaskProvider.INSTANCE);
// Register all blocks. Because blockids are unique to a world, this must be done each load
GameData.getBlockRegistry().typeSafeIterable().forEach(o -> {
AngelicaBlockSafetyRegistry.canBlockRenderOffThread(o, true, true);
AngelicaBlockSafetyRegistry.canBlockRenderOffThread(o, false, true);
});
}
}
@Override
public void init(FMLInitializationEvent event) {
super.init(event);
@@ -170,7 +150,6 @@ public final class ClientProxy extends CommonProxy {
}
}
@Override
public void postInit(FMLPostInitializationEvent event) {
super.postInit(event);
@@ -190,11 +169,38 @@ public final class ClientProxy extends CommonProxy {
}
}
@SubscribeEvent
public void worldLoad(WorldEvent.Load event) {
if (!event.world.isRemote) return;
if (GLStateManager.isRunningSplash()) {
GLStateManager.setRunningSplash(false);
LOGGER.info("World loaded - Enabling GLSM Cache");
}
if (AngelicaConfig.enableCeleritas) {
ChunkTaskRegistry.reset();
ChunkTaskRegistry.registerProvider(DefaultChunkTaskProvider.INSTANCE);
ChunkTaskRegistry.registerProvider(ThreadedChunkTaskProvider.INSTANCE);
// Register all blocks. Because blockids are unique to a world, this must be done each load
GameData.getBlockRegistry().typeSafeIterable().forEach(o -> {
AngelicaBlockSafetyRegistry.canBlockRenderOffThread(o, true, true);
AngelicaBlockSafetyRegistry.canBlockRenderOffThread(o, false, true);
});
}
}
@SubscribeEvent
public void onWorldUnload(WorldEvent.Unload event) {
if (!event.world.isRemote) return;
DynamicLights.get().removeAllLightSources();
}
float lastIntegratedTickTime;
@SubscribeEvent
public void onTick(TickEvent.ServerTickEvent event) {
if (FMLCommonHandler.instance().getSide().isClient() && event.phase == TickEvent.Phase.END) {
if (event.phase == TickEvent.Phase.END) {
final IntegratedServer srv = Minecraft.getMinecraft().getIntegratedServer();
if (srv != null) {
final long currentTickTime = srv.tickTimeArray[srv.getTickCounter() % 100];