From 1c3da8e244eb6ccacf569bb9ef1642063d37c432 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 13 Feb 2021 14:13:57 -0600 Subject: [PATCH] Clean up LOD generation threads stopping unexpectedly This doesn't fix the problem, it just prevents the threads from causing trouble in the main thread. --- .../com/backsun/lod/proxy/ClientProxy.java | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/backsun/lod/proxy/ClientProxy.java b/src/main/java/com/backsun/lod/proxy/ClientProxy.java index 032627a07..0a8ac75a9 100644 --- a/src/main/java/com/backsun/lod/proxy/ClientProxy.java +++ b/src/main/java/com/backsun/lod/proxy/ClientProxy.java @@ -172,42 +172,52 @@ public class ClientProxy extends CommonProxy Thread thread = new Thread(() -> { - LodChunk lod = new LodChunk(chunk, mc.world); - LodDimension lodDim; - - if (lodWorld == null) + try { - lodWorld = new LodWorld(LodFileHandler.getWorldName()); - } - else - { - // if we have a lodWorld make sure - // it is for this minecraft world - if (!lodWorld.worldName.equals(LodFileHandler.getWorldName())) + LodChunk lod = new LodChunk(chunk, mc.world); + LodDimension lodDim; + + if (lodWorld == null) { - // this lodWorld isn't for this minecraft world - // delete it so we can get a new one - lodWorld = null; - - // skip this frame - // we'll get this set up next time - return; + lodWorld = new LodWorld(LodFileHandler.getWorldName()); } + else + { + // if we have a lodWorld make sure + // it is for this minecraft world + if (!lodWorld.worldName.equals(LodFileHandler.getWorldName())) + { + // this lodWorld isn't for this minecraft world + // delete it so we can get a new one + lodWorld = null; + + // skip this frame + // we'll get this set up next time + return; + } + } + + + if (lodWorld.getLodDimension(dimId) == null) + { + DimensionType dim = DimensionType.getById(dimId); + lodDim = new LodDimension(dim, regionWidth); + lodWorld.addLodDimension(lodDim); + } + else + { + lodDim = lodWorld.getLodDimension(dimId); + } + + lodDim.addLod(lod); } - - - if (lodWorld.getLodDimension(dimId) == null) + catch(IllegalArgumentException | NullPointerException e) { - DimensionType dim = DimensionType.getById(dimId); - lodDim = new LodDimension(dim, regionWidth); - lodWorld.addLodDimension(lodDim); - } - else - { - lodDim = lodWorld.getLodDimension(dimId); + // if the world changes while LODs are being generated + // they will throw errors as they try to access things that no longer + // exist. } - lodDim.addLod(lod); }); lodGenThreadPool.execute(thread);