From 0e215e98d55fd2e8d588c88310503f9494414147 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 4 Jun 2023 16:22:21 +0100 Subject: [PATCH] fix: minor changes to fix loading blocks outside stored range in ThreadUnsafeCharBlocks (#2260) - Fixes #2258 --- .../implementation/blocks/ThreadUnsafeCharBlocks.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/ThreadUnsafeCharBlocks.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/ThreadUnsafeCharBlocks.java index 9f0aedc11..7d041155b 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/ThreadUnsafeCharBlocks.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/blocks/ThreadUnsafeCharBlocks.java @@ -98,12 +98,19 @@ public class ThreadUnsafeCharBlocks implements IChunkSet, IBlocks { public char[] load(int layer) { updateSectionIndexRange(layer); layer -= minSectionPosition; - return blocks[layer]; + char[] arr = blocks[layer]; + if (arr == null) { + arr = blocks[layer] = new char[FaweCache.INSTANCE.BLOCKS_PER_LAYER]; + } + return arr; } @Nullable @Override public char[] loadIfPresent(int layer) { + if (layer < minSectionPosition || layer > maxSectionPosition) { + return null; + } layer -= minSectionPosition; return blocks[layer]; } @@ -439,8 +446,8 @@ public class ThreadUnsafeCharBlocks implements IChunkSet, IBlocks { public IChunkSet createCopy() { char[][] blocksCopy = new char[sectionCount][]; for (int i = 0; i < sectionCount; i++) { + blocksCopy[i] = new char[FaweCache.INSTANCE.BLOCKS_PER_LAYER]; if (blocks[i] != null) { - blocksCopy[i] = new char[FaweCache.INSTANCE.BLOCKS_PER_LAYER]; System.arraycopy(blocks[i], 0, blocksCopy[i], 0, FaweCache.INSTANCE.BLOCKS_PER_LAYER); } }