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 d79be8372..c44143d86 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 @@ -393,7 +393,12 @@ public class SharedApi { for (IChunkWrapper adjacentChunk : nearbyChunkList) { - queueChunkUpdate(adjacentChunk, getNeighbourChunkListForChunk(adjacentChunk, dhLevel), dhLevel, true); + // pulling a new chunkWrapper is necessary to prevent concurrent modification on the existing chunkWrappers + IChunkWrapper newCenterChunk = dhLevel.getLevelWrapper().tryGetChunk(adjacentChunk.getChunkPos()); + if (newCenterChunk != null) + { + queueChunkUpdate(newCenterChunk, getNeighbourChunkListForChunk(newCenterChunk, dhLevel), dhLevel, true); + } } } @@ -620,15 +625,15 @@ public class SharedApi public UpdateChunkData popClosest() { - if (this.closestQueue.isEmpty()) - { - return null; - } - try { this.lock.lock(); + if (this.closestQueue.isEmpty()) + { + return null; + } + DhChunkPos closest = this.closestQueue.poll(); this.furthestQueue.remove(closest); return this.positionMap.remove(closest);