diff --git a/lib/init.lua b/lib/init.lua index 203ca97..9ba870c 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -469,14 +469,17 @@ function World.set(world: World, entityId: i53, componentId: i53, data: unknown) to.columns[archetypeRecord][record.row] = data end -local function archetypeTraverseRemove(world: World, componentId: i53, archetype: Archetype?): Archetype - local from = (archetype or world.ROOT_ARCHETYPE) :: Archetype +local function archetypeTraverseRemove(world: World, componentId: i53, from: Archetype): Archetype local edge = ensureEdge(from, componentId) local remove = edge.remove if not remove then local to = table.clone(from.types) - table.remove(to, table.find(to, componentId)) + local at = table.find(to, componentId) + if not at then + return from + end + table.remove(to, at) remove = ensureArchetype(world, to, from) edge.remove = remove :: never end diff --git a/tests/world.lua b/tests/world.lua index 30e5558..5dd3f95 100644 --- a/tests/world.lua +++ b/tests/world.lua @@ -160,7 +160,7 @@ TEST("world", function() end - do CASE "show allow remove that doesn't exist on entity" + do CASE "should allow remove that doesn't exist on entity" local world = jecs.World.new() local Health = world:entity() @@ -171,6 +171,7 @@ TEST("world", function() world:remove(id, Poison) CHECK(world:get(id, Poison) == nil) + print(world:get(id, Health)) CHECK(world:get(id, Health) == 50) end