Inside your for-loop, when you call Entity.destroy, you are not breaking out of the loop. As such, if the len is greater than 1, the Entity.destroy is called multiple times (if bullet hit a block seam, anyway), and I assume that's where you try to remove the bullet from the bump world, leading to your error.
You could simply change it to something like:
Code: Select all
local destroyed = false
for i=1, len do
local col = cols[i]
local other = col.other
local kind = other.class.name
if kind == 'Enemy' then
self:damageItem(other)
return
elseif kind == 'Block' then
destroyed = true
elseif kind == 'Player' then
return "cross"
end
if other ~= parent or not self.ignoresParent then
local nx, ny = col.normal.x, col.normal.y
self:changeVelocityByCollisionNormal(nx,ny)
end
end
if destroyed then
Entity.destroy(self)
return
end
Because you probably want to check all collisions before deleting the bullet (the bullet might hit an enemy and a floor block on the same frame), it's better to put the call to Entity.destroy after the loop has finished.
On a side note, I'm not sure why you have that kind == 'Player' comparison there. This would lead to a situation where if player and enemy are overlapping, the bullet might just not hit its target, leaving it entirely up to the order in which bump returns the collisions.