From 31f41540c0a8cde66527957d45bc6d5186e93e0b Mon Sep 17 00:00:00 2001 From: tom lee Date: Sat, 12 Feb 2022 15:13:58 +0800 Subject: [PATCH] Fix chat format color. Add failsafe stopping of generator --- .../config/LodConfigWrapperSingleton.java | 2 +- .../minecraft/MinecraftRenderWrapper.java | 4 +- .../BatchGenerationEnvironment.java | 39 +++++++++++++------ .../worldGeneration/GenerationEvent.java | 2 +- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/config/LodConfigWrapperSingleton.java b/common/src/main/java/com/seibel/lod/common/wrappers/config/LodConfigWrapperSingleton.java index f84eb028e..f9993c7d6 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/config/LodConfigWrapperSingleton.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/config/LodConfigWrapperSingleton.java @@ -361,7 +361,7 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton @Override public boolean getEnableDistantGeneration() { - return Config.Client.WorldGenerator.enableDistantGeneration; + return (boolean) ConfigGui.editSingleOption.getEntry("client.worldGenerator.enableDistantGeneration").value; } @Override public void setEnableDistantGeneration(boolean newEnableDistantGeneration) diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftRenderWrapper.java b/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftRenderWrapper.java index c7ff68b5d..a04911f02 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftRenderWrapper.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/minecraft/MinecraftRenderWrapper.java @@ -178,10 +178,10 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper } catch (LinkageError e) { try { MinecraftWrapper.INSTANCE.sendChatMessage( - "&e&l&uWRANING: Distant Horizons: getVanillaRenderedChunks method failed." + "\u00A7e\u00A7l\u00A7uWRANING: Distant Horizons: getVanillaRenderedChunks method failed." + " Using Backup Method."); MinecraftWrapper.INSTANCE.sendChatMessage( - "&eOverdraw prevention will be worse than normal."); + "\u00A7eOverdraw prevention will be worse than normal."); } catch (Exception e2) {} ClientApi.LOGGER.error("getVanillaRenderedChunks Error: {}", e); usingBackupGetVanillaRenderedChunks = true; diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java index 87c62e62e..f08f6190c 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/BatchGenerationEnvironment.java @@ -226,6 +226,10 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv //public boolean safeMode = false; private static final ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class); private static final IMinecraftWrapper MC = SingletonHandler.get(IMinecraftWrapper.class); + public static final long EXCEPTION_TIMER_RESET_TIME = TimeUnit.NANOSECONDS.convert(1, TimeUnit.SECONDS); + public static final int EXCEPTION_COUNTER_TRIGGER = 20; + public int unknownExceptionCount = 0; + public long lastExceptionTriggerTime = 0; public static final LodThreadFactory threadFactory = new LodThreadFactory("Gen-Worker-Thread", Thread.MIN_PRIORITY); @@ -234,15 +238,14 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv public T joinSync(CompletableFuture f) { if (!unsafeThreadingRecorded && !f.isDone()) { - MC.sendChatMessage("&4&l&uERROR: Distant Horizons: Unsafe Threading in Chunk Generator Detected!"); - MC.sendChatMessage("&eTo increase stability, it is recommended to set world generation threads count to 1."); + MC.sendChatMessage("\u00A74\u00A7l\u00A7uERROR: Distant Horizons: Unsafe Threading in Chunk Generator Detected!"); + MC.sendChatMessage("\u00A7eTo increase stability, it is recommended to set world generation threads count to 1."); ClientApi.LOGGER.error("Unsafe Threading in Chunk Generator: ", new RuntimeException("Concurrent future")); unsafeThreadingRecorded = true; } return f.join(); } - public void resizeThreadPool(int newThreadCount) { executors = Executors.newFixedThreadPool(newThreadCount, @@ -267,6 +270,12 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv public void updateAllFutures() { + if (unknownExceptionCount > 0) { + if (System.nanoTime() - lastExceptionTriggerTime >= EXCEPTION_TIMER_RESET_TIME) { + unknownExceptionCount = 0; + } + } + // Update all current out standing jobs Iterator iter = events.iterator(); while (iter.hasNext()) @@ -280,12 +289,10 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv } catch (Throwable e) { - e.printStackTrace(); - while (e.getCause() != null) - { - e = e.getCause(); - e.printStackTrace(); - } + ClientApi.LOGGER.error("Batching World Generator: Event {} gotten an exception", event); + ClientApi.LOGGER.error("Exception: ", e); + unknownExceptionCount++; + lastExceptionTriggerTime = System.nanoTime(); } finally { @@ -307,6 +314,14 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv } } } + if (unknownExceptionCount > EXCEPTION_COUNTER_TRIGGER) { + try { + MC.sendChatMessage("\u00A74\u00A7l\u00A7uERROR: Distant Horizons: Too many exceptions in Batching World Generator! Disabling the generator."); + } catch (Exception e) {} + ClientApi.LOGGER.error("Too many exceptions in Batching World Generator! Now disabling."); + unknownExceptionCount = 0; + CONFIG.client().worldGenerator().setEnableDistantGeneration(false); + } } public BatchGenerationEnvironment(IWorldWrapper serverlevel, LodBuilder lodBuilder, LodDimension lodDim) @@ -317,8 +332,9 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv if (!(generator instanceof NoiseBasedChunkGenerator || generator instanceof DebugLevelSource || generator instanceof FlatLevelSource)) { - MC.sendChatMessage("&4&l&uWARNING: Distant Horizons: Unknown Chunk Generator Detected! Distant Generation May Fail!"); - MC.sendChatMessage("&eIf it does crash, set Distant Generation to OFF or Generation Mode to None."); + MC.sendChatMessage("\u00A74\u00A7l\u00A7uWARNING: Distant Horizons: Unknown Chunk Generator Detected! Distant Generation May Fail!"); + MC.sendChatMessage("\u00A7eIf it does crash, set Distant Generation to OFF or Generation Mode to None."); + ClientApi.LOGGER.warn("Unknown Chunk Generator detected: {}", generator.getClass()); } params = new GlobalParameters((ServerLevel) ((WorldWrapper) serverlevel).getWorld(), lodBuilder, lodDim); } @@ -384,7 +400,6 @@ public final class BatchGenerationEnvironment extends AbstractBatchGenerationEnv catch (RuntimeException e2) { // Continue... - e2.printStackTrace(); } if (target == null) target = new ProtoChunk(chunkPos, UpgradeData.EMPTY, params.level, diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GenerationEvent.java b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GenerationEvent.java index c65c8726a..4dfd85305 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GenerationEvent.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/worldGeneration/GenerationEvent.java @@ -78,7 +78,7 @@ public final class GenerationEvent } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); + throw new RuntimeException(e.getCause()==null? e : e.getCause()); } }