always check OnDelete condition

This commit is contained in:
Ukendio 2025-07-17 23:45:03 +02:00
parent ebc39c8b28
commit 9c09686a69
2 changed files with 23 additions and 9 deletions

View file

@ -714,13 +714,13 @@ local function id_record_ensure(world: World, id: Entity): ComponentRecord
if world_has_one_inline(world, relation, EcsExclusive) then if world_has_one_inline(world, relation, EcsExclusive) then
is_exclusive = true is_exclusive = true
end end
else end
local cleanup_policy = world_target(world, relation, EcsOnDelete, 0) local cleanup_policy = world_target(world, relation, EcsOnDelete, 0)
if cleanup_policy == EcsDelete then if cleanup_policy == EcsDelete then
has_delete = true has_delete = true
end end
end
local on_add, on_change, on_remove = world_get(world, local on_add, on_change, on_remove = world_get(world,
relation, EcsOnAdd, EcsOnChange, EcsOnRemove) relation, EcsOnAdd, EcsOnChange, EcsOnRemove)
@ -2766,7 +2766,7 @@ local function world_new()
if idr then if idr then
local flags = idr.flags local flags = idr.flags
if bit32.btest(flags, ECS_ID_DELETE) then if (bit32.btest(flags, ECS_ID_DELETE) == true) then
for archetype_id in idr.records do for archetype_id in idr.records do
local idr_archetype = archetypes[archetype_id] local idr_archetype = archetypes[archetype_id]
@ -2873,7 +2873,8 @@ local function world_new()
if idr_r then if idr_r then
local archetype_ids = idr_r.records local archetype_ids = idr_r.records
local flags = idr_r.flags local flags = idr_r.flags
if bit32.btest(flags, ECS_ID_DELETE) then local has_delete_policy = bit32.btest(flags, ECS_ID_DELETE)
if has_delete_policy then
for archetype_id in archetype_ids do for archetype_id in archetype_ids do
local idr_r_archetype = archetypes[archetype_id] local idr_r_archetype = archetypes[archetype_id]
local entities = idr_r_archetype.entities local entities = idr_r_archetype.entities

View file

@ -24,6 +24,19 @@ type Id<T=unknown> = jecs.Id<T>
local entity_visualiser = require("@tools/entity_visualiser") local entity_visualiser = require("@tools/entity_visualiser")
local dwi = entity_visualiser.stringify local dwi = entity_visualiser.stringify
TEST("ardi", function()
local world = jecs.world()
local r = world:entity()
world:add(r, jecs.pair(jecs.OnDelete, jecs.Delete))
local e = world:entity()
local e1 = world:entity()
world:add(e, jecs.pair(r, e1))
world:delete(r)
CHECK(not world:contains(e))
end)
TEST("dai", function() TEST("dai", function()
local world = jecs.world() local world = jecs.world()
local C = world:component() local C = world:component()
@ -621,9 +634,9 @@ TEST("world:delete()", function()
world:add(e1, ct) world:add(e1, ct)
world:add(e2, jecs.pair(ct, dummy)) world:add(e2, jecs.pair(ct, dummy))
world:delete(dummy) -- world:delete(dummy)
CHECK(world:contains(e2)) -- CHECK(world:contains(e2))
world:delete(ct) world:delete(ct)