From d2f5c0223861b8a44acf636fe8da8942dee40fab Mon Sep 17 00:00:00 2001 From: s809 <43530948+s809@users.noreply.github.com> Date: Sun, 12 Nov 2023 17:17:15 +0500 Subject: [PATCH] Bandaid fix to prevent duplicate section requests --- .../core/generation/WorldRemoteGenerationQueue.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldRemoteGenerationQueue.java b/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldRemoteGenerationQueue.java index 235c65a9d..e06204bfc 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldRemoteGenerationQueue.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/generation/WorldRemoteGenerationQueue.java @@ -51,6 +51,8 @@ public class WorldRemoteGenerationQueue implements IWorldGenerationQueue, IDebug private final AtomicInteger finishedRequests = new AtomicInteger(); private final AtomicInteger failedRequests = new AtomicInteger(); + private final Set alreadyGeneratedPosHashSet = ConcurrentHashMap.newKeySet(); + public WorldRemoteGenerationQueue(ClientNetworkState networkState, IDhClientLevel level) { this.networkState = networkState; @@ -75,6 +77,15 @@ public class WorldRemoteGenerationQueue implements IWorldGenerationQueue, IDebug { LodUtil.assertTrue(sectionPos.getDetailLevel() == DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL, "Only highest-detail sections are allowed."); + // check if this is a duplicate generation task + if (this.alreadyGeneratedPosHashSet.contains(sectionPos)) + { + // temporary solution to prevent generating the same section multiple times + LOGGER.trace("Duplicate generation section " + sectionPos + ". Skipping..."); + return CompletableFuture.completedFuture(WorldGenResult.CreateFail()); + } + this.alreadyGeneratedPosHashSet.add(sectionPos); + WorldGenQueueEntry entry = new WorldGenQueueEntry(new CompletableFuture<>(), tracker); waitingTasks.put(sectionPos, entry); return entry.future; @@ -149,6 +160,7 @@ public class WorldRemoteGenerationQueue implements IWorldGenerationQueue, IDebug entry.future.cancel(false); if (entry.request != null) entry.request.cancel(false); + alreadyGeneratedPosHashSet.remove(pos); } } }