From d30aae862f6b56149218a7f3a1b730a5be91b59a Mon Sep 17 00:00:00 2001 From: LexManos Date: Mon, 9 May 2016 02:10:24 -0700 Subject: [PATCH] Fixed issue in ChunkIO that would potentially cause NPEs on chunks. Closes #2837 --- .../common/chunkio/ChunkIOExecutor.java | 4 ++-- .../common/chunkio/ChunkIOProvider.java | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/minecraftforge/common/chunkio/ChunkIOExecutor.java b/src/main/java/net/minecraftforge/common/chunkio/ChunkIOExecutor.java index 0e46a9fd2..cc710132d 100644 --- a/src/main/java/net/minecraftforge/common/chunkio/ChunkIOExecutor.java +++ b/src/main/java/net/minecraftforge/common/chunkio/ChunkIOExecutor.java @@ -47,9 +47,9 @@ public class ChunkIOExecutor { if (!pool.remove(task)) // If it wasn't in the pool, and run hasn't finished, then wait for the async thread. { - while (!task.runFinished()) + synchronized(task) { - synchronized(task) + while (!task.runFinished()) { try { diff --git a/src/main/java/net/minecraftforge/common/chunkio/ChunkIOProvider.java b/src/main/java/net/minecraftforge/common/chunkio/ChunkIOProvider.java index b76a7cfd6..8399d3f9b 100644 --- a/src/main/java/net/minecraftforge/common/chunkio/ChunkIOProvider.java +++ b/src/main/java/net/minecraftforge/common/chunkio/ChunkIOProvider.java @@ -67,7 +67,8 @@ class ChunkIOProvider implements Runnable if (chunk == null) { // If the chunk loading failed just do it synchronously (may generate) - provider.originalLoadChunk(this.chunkInfo.x, this.chunkInfo.z); + this.chunk = provider.originalLoadChunk(this.chunkInfo.x, this.chunkInfo.z); + this.runCallbacks(); return; } @@ -87,13 +88,7 @@ class ChunkIOProvider implements Runnable } this.chunk.populateChunk(provider, provider.chunkGenerator); - - for (Runnable r : this.callbacks) - { - r.run(); - } - - this.callbacks.clear(); + this.runCallbacks(); } public Chunk getChunk() @@ -110,4 +105,14 @@ class ChunkIOProvider implements Runnable { return this.callbacks.size() > 0; } + + public void runCallbacks() + { + for (Runnable r : this.callbacks) + { + r.run(); + } + + this.callbacks.clear(); + } } \ No newline at end of file