Fixed world:delete() not invoking OnRemove hooks. (#178)

* Fixed cached wildcard queries

* Fixed world:delete() not calling OnRemove hook

* Typo in hooks fix

* Fixed test case

* Fixed test case (again)

* Fixed test case (again 2x)

* Now it should work
This commit is contained in:
Intrinsic 2025-01-16 15:45:29 -08:00 committed by GitHub
parent 669c216387
commit c354a29fb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 1 deletions

View file

@ -957,8 +957,10 @@ local function archetype_delete(world: World, archetype: Archetype, row: number,
-- TODO: if last == 0 then deactivate table -- TODO: if last == 0 then deactivate table
local component_index = world.componentIndex
for _, id in id_types do for _, id in id_types do
local on_remove: (entity: i53) -> () = world_get_one_inline(world, id, EcsOnRemove) local idr = component_index[id]
local on_remove = idr.hooks.on_remove
if on_remove then if on_remove then
on_remove(delete) on_remove(delete)
end end

View file

@ -1659,4 +1659,47 @@ TEST("wildcard query", function()
CHECK(counter == 1) CHECK(counter == 1)
end end
end) end)
TEST("world:delete() invokes OnRemove hook", function()
do CASE "#1"
local world = world_new()
local A = world:entity()
local entity = world:entity()
local called = false
world:set(A, jecs.OnRemove, function(e)
called = true
end)
world:add(entity, A)
world:delete(entity)
CHECK(called)
end
do CASE "#2"
local world = world_new()
local pair = jecs.pair
local Relation = world:entity()
local A = world:entity()
local B = world:entity()
world:add(Relation, pair(jecs.OnDelete, jecs.Delete))
local entity = world:entity()
local called = false
world:set(A, jecs.OnRemove, function(e)
called = true
end)
world:add(entity, A)
world:add(entity, pair(Relation, B))
world:delete(B)
CHECK(called)
end
end)
FINISH() FINISH()