Fix entity deletion swap logic

This commit is contained in:
Ukendio 2025-03-01 20:15:52 +01:00
parent 1bfcba7422
commit a5dad9aa4d
2 changed files with 17 additions and 0 deletions

View file

@ -950,6 +950,7 @@ local function archetype_delete(world: World, archetype: Archetype, row: number,
record_to_move.row = row record_to_move.row = row
end end
delete = entities[row]
entities[row] = move entities[row] = move
end end

View file

@ -1045,6 +1045,22 @@ TEST("world:component()", function()
end) end)
TEST("world:delete", function() TEST("world:delete", function()
do CASE "invoke OnRemove hooks"
local world = world_new()
local e1 = world:entity()
local e2 = world:entity()
local Stable = world:component()
world:set(Stable, jecs.OnRemove, function(e)
CHECK(e == e1)
end)
world:set(e1, Stable, true)
world:set(e2, Stable, true)
world:delete(e1)
end
do CASE "delete recycled entity id used as component" do CASE "delete recycled entity id used as component"
local world = world_new() local world = world_new()
local id = world:entity() local id = world:entity()