Fix bug to allow deletion outside partitioned range

This commit is contained in:
Ukendio 2025-07-06 17:07:40 +02:00
parent eed1b6179e
commit 29350e6ec3
2 changed files with 25 additions and 4 deletions

View file

@ -2174,7 +2174,7 @@ local function world_new()
local function inner_entity_index_try_get_any(entity: number): Record?
local r = eindex_sparse_array[ECS_ENTITY_T_LO(entity)]
if not r or r.dense == 0 then
if not r then
return nil
end
@ -2589,7 +2589,7 @@ local function world_new()
return entity
else
for i = eindex_max_id + 1, index do
eindex_sparse_array[i]= { dense = i } :: Record
eindex_sparse_array[i] = { dense = i } :: Record
eindex_dense_array[i] = i
end
entity_index.max_id = index
@ -2911,7 +2911,6 @@ local function world_new()
local e_swap = dense_array[i_swap]
local r_swap = inner_entity_index_try_get_any(e_swap :: number) :: Record
r_swap.dense = dense
record.archetype = nil :: any
record.row = nil :: any

View file

@ -659,7 +659,6 @@ TEST("world:delete()", function()
CHECK(not world:has(id1, Health))
end
do CASE "delete children"
local world = jecs.world()
@ -846,6 +845,16 @@ TEST("world:delete()", function()
CHECK(not world:contains(bob))
CHECK(not world:contains(alice))
end
do CASE "deleted entity should not be able to be operated on"
local world = jecs.world()
local e = world:entity()
local A = world:component()
world:set(e, A, true)
world:delete(e)
world:set(e, A, true)
CHECK(world:has(e, A) == false)
end
end)
TEST("world:each()", function()
@ -877,6 +886,19 @@ TEST("world:each()", function()
end)
TEST("world:range()", function()
do CASE "delete outside partitioned range"
local server = jecs.world()
local client = jecs.world()
server:range(0, 1000)
client:range(1000, 5000)
local e1 = server:entity()
CHECK((e1::number)< 1000)
local e2 = client:entity(e1)
CHECK(e2 == e1)
client:delete(e1)
end
do CASE "under range start"
local world = jecs.world()
world:range(400, 1000)