From d1b0866af202b24a706682038d397fe2977fe2f5 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sat, 7 Aug 2021 02:30:38 +0100 Subject: [PATCH] //floodfill: fix crash --- CHANGELOG.md | 1 + worldeditadditions/lib/floodfill.lua | 5 ++++- worldeditadditions/utils/queue.lua | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bd2957..5d81f91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Note to self: See the bottom of this file for the release template text. - `//layers`: Add optional slope constraint (inspired by [WorldPainter](https://worldpainter.net/)) - `//bonemeal`: Add optional node list constraint - `//walls`: Add optional thickness argument + - `//floodfill`: Fix crash caused by internal refactoring of the `Queue` data structure ## v1.12: The selection tools update (26th June 2021) diff --git a/worldeditadditions/lib/floodfill.lua b/worldeditadditions/lib/floodfill.lua index bfefe28..386bb07 100644 --- a/worldeditadditions/lib/floodfill.lua +++ b/worldeditadditions/lib/floodfill.lua @@ -28,12 +28,15 @@ function worldeditadditions.floodfill(start_pos, radius, replace_node) local count = 0 local remaining_nodes = wea.Queue.new() - remaining_nodes:enqueue(start_pos_index) + print("DEBUG enqueue start_pos_index", start_pos_index) + print("DEBUG enqueued id", remaining_nodes:enqueue(start_pos_index)) -- Do the floodfill while remaining_nodes:is_empty() == false do local cur = remaining_nodes:dequeue() + print("DEBUG cur", cur) + -- Replace this node data[cur] = replace_id count = count + 1 diff --git a/worldeditadditions/utils/queue.lua b/worldeditadditions/utils/queue.lua index a00f1e5..197ff2e 100644 --- a/worldeditadditions/utils/queue.lua +++ b/worldeditadditions/utils/queue.lua @@ -61,7 +61,7 @@ function Queue:dequeue() -- Find the next non-nil item local value while value == nil do - if first >= self.last then return nil end + if first > self.last then return nil end value = self.items[first] self.items[first] = nil -- Help the garbage collector out first = first + 1