Skip to content

Commit

Permalink
Prevent iterator invalidation in world:each
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio committed Dec 21, 2024
1 parent 4841915 commit 02cb4ad
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions jecs.luau
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 02cb4ad

Please sign in to comment.