aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ecs.lua7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/ecs.lua b/src/ecs.lua
index 373d338..a1dab27 100644
--- a/src/ecs.lua
+++ b/src/ecs.lua
@@ -83,9 +83,10 @@ local function remove_comp(ent, comp)
local lastid = mask.dense[mask.size]
mask.sparse[ent.id] = nil
- mask.sparse[lastid] = index
-
- mask.dense[index] = mask.dense[mask.size]
+ if ent.id ~= lastid then
+ mask.sparse[lastid] = index
+ mask.dense[index] = mask.dense[mask.size]
+ end
mask.dense[mask.size] = nil
mask.size = mask.size - 1
end