From 04d7238383466b15dc661f440f8ca383f450ad3e Mon Sep 17 00:00:00 2001 From: Aeden McClain Date: Mon, 30 Dec 2024 10:15:15 -0800 Subject: [PATCH] object: when cleaning up dropped items, only re-add ones that aren't already in the recycle bin. (#1324) Signed-off-by: Aeden McClain --- src/module.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/module.zig b/src/module.zig index b0f7b8ba..97c1c9a4 100644 --- a/src/module.zig +++ b/src/module.zig @@ -140,7 +140,14 @@ pub fn Objects(options: ObjectsOptions, comptime T: type) type { // recycling bin to fit them. if (objs.internal.thrown_on_the_floor >= (data.len / 10)) { var iter = dead.iterator(.{ .kind = .set }); - while (iter.next()) |index| { + dead_object_loop: while (iter.next()) |index| { + // We need to check if this index is already in the recycling bin since + // if it is, it could get recycled a second time while still + // in use. + for (recycling_bin.items) |recycled_index| { + if (index == recycled_index) continue :dead_object_loop; + } + // dead bitset contains data.capacity number of entries, we only care about ones that are in data.len range. if (index > data.len - 1) break; try recycling_bin.append(allocator, @intCast(index));