Fix bulk_insert not ensuring that archetype ids are sorted (#277)

* Fix bulk_insert not ensuring archetype ids are sorted

* Add test case
This commit is contained in:
Axen 2025-09-09 14:11:55 +03:00 committed by GitHub
parent af093713b4
commit d8b2d36c52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View file

@ -2050,7 +2050,9 @@ local function ecs_bulk_insert(world: world, entity: i53, ids: { i53 }, values:
local from = r.archetype local from = r.archetype
local component_index = world.component_index local component_index = world.component_index
if not from then if not from then
local dst_types = ids local dst_types = table.clone(ids)
table.sort(dst_types)
local to = archetype_ensure(world, dst_types) local to = archetype_ensure(world, dst_types)
new_entity(entity, r, to) new_entity(entity, r, to)
local ROOT_ARCHETYPE = world.ROOT_ARCHETYPE local ROOT_ARCHETYPE = world.ROOT_ARCHETYPE

View file

@ -330,6 +330,20 @@ TEST("bulk", function()
CHECK(world:get(e, c2) == 123) CHECK(world:get(e, c2) == 123)
CHECK(world:get(e, c3) == "hello") CHECK(world:get(e, c3) == "hello")
end end
do CASE "Should ensure archetype ids are sorted"
local world = jecs.world()
local c1, c2, c3 = world:component(), world:component(), world:component()
local e = world:entity()
jecs.bulk_insert(world, e, { c2, c1 }, { 2, 1 })
jecs.bulk_insert(world, e, { c1 }, { 1 })
world:set(e, c3, 3)
CHECK(world:get(e, c1) == 1)
CHECK(world:get(e, c2) == 2)
CHECK(world:get(e, c3) == 3)
end
end) end)
TEST("repro", function() TEST("repro", function()