From 02cb4ad7a29ac682b6be9c13ad3f7ba832913956 Mon Sep 17 00:00:00 2001 From: Ukendio Date: Sat, 21 Dec 2024 06:51:48 +0100 Subject: [PATCH] Prevent iterator invalidation in world:each --- jecs.luau | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/jecs.luau b/jecs.luau index f7eea3c4..b014db24 100644 --- a/jecs.luau +++ b/jecs.luau @@ -1562,17 +1562,21 @@ local function world_each(world: World, id): () -> () return NOOP end - local last = 0 + local entities = archetype.entities + local row = #entities + return function(): any - last += 1 - local entity = archetype.entities[last] + local entity = entities[row] while not entity do archetype_id = next(idr_cache, archetype_id) if not archetype_id then return end archetype = archetypes[archetype_id] + entities = archetype.entities + row = #entities end + row -= 1 return entity end end