From 991c77485d08ebf1a436c0dcb229bb2692997e5b Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 14 Dec 2024 20:57:22 -0600 Subject: [PATCH] Fix concurrent ChunkWrapper modifications in SharedApi --- .../core/api/internal/SharedApi.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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);