2019-04-23 06:47:07 +02:00
From 036c518050a0972307568a014156d59bb90bf54c Mon Sep 17 00:00:00 2001
2016-05-28 04:28:23 +02:00
From: Aikar <aikar@aikar.co>
Date: Fri, 27 May 2016 21:41:26 -0400
Subject: [PATCH] Ensure Chunks never ever load async
Safely pushes the operation to main thread, then back to the posting thread
diff --git a/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOExecutor.java b/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOExecutor.java
2018-09-29 01:31:59 +02:00
index e4fd9bc604..7ffb8f6172 100644
2016-05-28 04:28:23 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOExecutor.java
+++ b/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOExecutor.java
2018-09-29 01:31:59 +02:00
@@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.chunkio;
2016-05-28 04:28:23 +02:00
import net.minecraft.server.Chunk;
import net.minecraft.server.ChunkProviderServer;
import net.minecraft.server.ChunkRegionLoader;
+import net.minecraft.server.MCUtil; // Paper
import net.minecraft.server.World;
import org.bukkit.craftbukkit.util.AsynchronousExecutor;
2018-09-29 01:31:59 +02:00
@@ -13,7 +14,7 @@ public class ChunkIOExecutor {
2016-05-28 04:28:23 +02:00
private static final AsynchronousExecutor<QueuedChunk, Chunk, Runnable, RuntimeException> instance = new AsynchronousExecutor<QueuedChunk, Chunk, Runnable, RuntimeException>(new ChunkIOProvider(), BASE_THREADS);
public static Chunk syncChunkLoad(World world, ChunkRegionLoader loader, ChunkProviderServer provider, int x, int z) {
- return instance.getSkipQueue(new QueuedChunk(x, z, loader, world, provider));
+ return MCUtil.ensureMain("Async Chunk Load", () -> instance.getSkipQueue(new QueuedChunk(x, z, loader, world, provider))); // Paper
}
public static void queueChunkLoad(World world, ChunkRegionLoader loader, ChunkProviderServer provider, int x, int z, Runnable runnable) {
diff --git a/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOProvider.java b/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOProvider.java
2018-08-26 20:11:49 +02:00
index 52a8c48fa4..4cfe24df15 100644
2016-05-28 04:28:23 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOProvider.java
+++ b/src/main/java/org/bukkit/craftbukkit/chunkio/ChunkIOProvider.java
2018-07-16 22:08:09 +02:00
@@ -35,9 +35,9 @@ class ChunkIOProvider implements AsynchronousExecutor.CallBackProvider<QueuedChu
2016-05-28 04:28:23 +02:00
// sync stuff
public void callStage2(QueuedChunk queuedChunk, Chunk chunk) throws RuntimeException {
- if (chunk == null) {
+ if (chunk == null || queuedChunk.provider.chunks.containsKey(ChunkCoordIntPair.a(queuedChunk.x, queuedChunk.z))) { // Paper - also call original if it was already loaded
2018-07-16 17:34:55 +02:00
// If the chunk loading failed just do it synchronously (may generate)
2018-07-16 22:08:09 +02:00
- // queuedChunk.provider.originalGetChunkAt(queuedChunk.x, queuedChunk.z);
2018-08-26 20:11:49 +02:00
+ queuedChunk.provider.getChunkAt(queuedChunk.x, queuedChunk.z, true, true); // Paper - actually call original if it was already loaded
2016-05-28 04:28:23 +02:00
return;
2018-07-16 22:08:09 +02:00
}
try (Timing ignored = queuedChunk.provider.world.timings.chunkIOStage2.startTimingIfSync()) { // Paper
2016-05-28 04:28:23 +02:00
--
2019-04-23 06:47:07 +02:00
2.21.0
2016-05-28 04:28:23 +02:00