Fix concurrent ChunkWrapper modifications in SharedApi

This commit is contained in:
James Seibel
2024-12-14 20:57:22 -06:00
parent de5e4a6705
commit 991c77485d
@@ -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);