diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java index db4043198..106c3e726 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/SharedApi.java @@ -99,6 +99,11 @@ public class SharedApi public static void setDhWorld(AbstractDhWorld newWorld) { + AbstractDhWorld oldWorld = currentWorld; + if (oldWorld != null) + { + oldWorld.close(); + } currentWorld = newWorld; // starting and stopping the DataRenderTransformer is necessary to prevent attempting to diff --git a/core/src/main/java/com/seibel/distanthorizons/core/util/threading/ThreadPoolUtil.java b/core/src/main/java/com/seibel/distanthorizons/core/util/threading/ThreadPoolUtil.java index fd8ab2291..d9cd5e348 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/util/threading/ThreadPoolUtil.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/util/threading/ThreadPoolUtil.java @@ -89,7 +89,14 @@ public class ThreadPoolUtil public static void setupThreadPools() { - // thread pools + //==================// + // main thread pool // + //==================// + + if (taskPicker != null) + { + taskPicker.shutdown(); + } taskPicker = new PriorityTaskPicker(); networkCompressionThreadPool = taskPicker.createExecutor(); @@ -98,8 +105,22 @@ public class ThreadPoolUtil updatePropagatorThreadPool = taskPicker.createExecutor(); worldGenThreadPool = taskPicker.createExecutor(); - // single thread pools + + + //=========================// + // standalone thread pools // + //=========================// + + if (beaconCullingThreadPool != null) + { + beaconCullingThreadPool.shutdown(); + } beaconCullingThreadPool = ThreadUtil.makeSingleThreadPool(BEACON_CULLING_THREAD_NAME); + + if (fullDataMigrationThreadPool != null) + { + fullDataMigrationThreadPool.shutdown(); + } fullDataMigrationThreadPool = ThreadUtil.makeSingleThreadPool(FULL_DATA_MIGRATION_THREAD_NAME); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/world/DhClientWorld.java b/core/src/main/java/com/seibel/distanthorizons/core/world/DhClientWorld.java index 958e82d05..97d3865e3 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/world/DhClientWorld.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/world/DhClientWorld.java @@ -39,8 +39,8 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld public final ClientOnlySaveStructure saveStructure; public final ClientNetworkState networkState = new ClientNetworkState(); - public ExecutorService dhTickerThread = ThreadUtil.makeSingleThreadPool("Client World Ticker Thread"); - public EventLoop eventLoop = new EventLoop(this.dhTickerThread, this::_clientTick); + public final ExecutorService dhTickerThread = ThreadUtil.makeSingleThreadPool("Client World Ticker Thread"); + public final EventLoop eventLoop = new EventLoop(this.dhTickerThread, this::_clientTick); @@ -128,6 +128,8 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld { this.networkState.close(); + this.dhTickerThread.shutdownNow(); + for (DhClientLevel dhClientLevel : this.levels.values()) {