From ddb41a9669eb6debef7afe17aa2741c6cda79770 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Mon, 11 Jan 2021 15:06:55 +0000 Subject: [PATCH] With "queueing" enabled, FAWE may start attempting to place chunks before the operation is finished. This is unnacceptable for recursive operations, thus the queue should be disable in these cases Fixes #842 --- .../implementation/blocks/CharBlocks.java | 34 ++++++++----------- .../java/com/sk89q/worldedit/EditSession.java | 16 +++++++++ 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharBlocks.java index 7264b47ba..4a10276e5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharBlocks.java @@ -26,30 +26,25 @@ public abstract class CharBlocks implements IBlocks { return true; } }; - protected static final Section EMPTY = new Section() { + protected final Section EMPTY = new Section() { @Override - public final char[] get(CharBlocks blocks, int layer) { - blocks.loadLock.lock(); - try { - char[] arr = blocks.blocks[layer]; + public final synchronized char[] get(CharBlocks blocks, int layer) { + char[] arr = blocks.blocks[layer]; + if (arr == null) { + arr = blocks.blocks[layer] = blocks.update(layer, null); if (arr == null) { - arr = blocks.blocks[layer] = blocks.update(layer, null); - if (arr == null) { - throw new IllegalStateException("Array cannot be null: " + blocks.getClass()); - } - } else { - blocks.blocks[layer] = blocks.update(layer, arr); - if (blocks.blocks[layer] == null) { - throw new IllegalStateException("Array cannot be null (update): " + blocks.getClass()); - } + throw new IllegalStateException("Array cannot be null: " + blocks.getClass()); } - if (blocks.blocks[layer] != null) { - blocks.sections[layer] = FULL; + } else { + blocks.blocks[layer] = blocks.update(layer, arr); + if (blocks.blocks[layer] == null) { + throw new IllegalStateException("Array cannot be null (update): " + blocks.getClass()); } - return arr; - } finally { - blocks.loadLock.unlock(); } + if (blocks.blocks[layer] != null) { + blocks.sections[layer] = FULL; + } + return arr; } @Override @@ -59,7 +54,6 @@ public abstract class CharBlocks implements IBlocks { }; public final char[][] blocks; public final Section[] sections; - private final ReentrantLock loadLock = new ReentrantLock (); public CharBlocks() { blocks = new char[16][]; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index 51e4672aa..60e2c92c2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -1179,6 +1179,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { // Pick how we're going to visit blocks RecursiveVisitor visitor = new DirectionalVisitor(mask, replace, origin, direction, (int) (radius * 2 + 1)); + // With queue enabled, FAWE may start attempting to place chunks before the operation is finished. + // This is unnacceptable for recursive operations. + disableQueue(); + // Start at the origin visitor.visit(origin); @@ -1237,6 +1241,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { visitor = new DownwardVisitor(mask, replace, origin.getBlockY(), (int) (radius * 2 + 1)); } + // With queue enabled, FAWE may start attempting to place chunks before the operation is finished. + // This is unnacceptable for recursive operations. + disableQueue(); + // Start at the origin visitor.visit(origin); @@ -1717,6 +1725,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { } RecursiveVisitor visitor = new RecursiveVisitor(mask, replace, (int) (radius * 2 + 1)); + // With queue enabled, FAWE may start attempting to place chunks before the operation is finished. + // This is unnacceptable for recursive operations. + disableQueue(); + // Around the origin in a 3x3 block for (BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) { if (mask.test(position)) { @@ -1758,6 +1770,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { BlockReplace replace = new BlockReplace(this, fluid.getDefaultState()); NonRisingVisitor visitor = new NonRisingVisitor(mask, replace); + // With queue enabled, FAWE may start attempting to place chunks before the operation is finished. + // This is unnacceptable for recursive operations. + disableQueue(); + // Around the origin in a 3x3 block for (BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) { if (liquidMask.test(position)) {