Entities that are removed from Ents table but not retired yet, may break the return table from TheSim:FindEntities with a nil value. I assume FindEntities translates GUIDs intro entities via the Ents table, so that's why it ends up with a nil.
Since ipairs is often used with FindEntities, this will cause the loop to stop at the nil value, skipping the rest of the table.
function EntityScript:Remove() if self.parent then self.parent:RemoveChild(self) end if self.platformfollowers then for k,v in pairs(self.platformfollowers) do k.platform = nil end end OnRemoveEntity(self.GUID) --Anything below that uses FindEntities may get a broken table self:PushEvent("onremove") --tell our listeners to forget about us self:StopAllWatchingWorldStates() self:RemoveAllEventCallbacks() self:CancelAllPendingTasks() for k, v in pairs(self.components) do if v and type(v) == "table" and v.OnRemoveEntity then v:OnRemoveEntity() end end for k, v in pairs(rawget(self.replica, "_")) do if v and type(v) == "table" and v.OnRemoveEntity then v:OnRemoveEntity() end end if self.updatecomponents then self.updatecomponents = nil UpdatingEnts[self.GUID] = nil num_updating_ents = num_updating_ents - 1 end NewUpdatingEnts[self.GUID] = nil if self.wallupdatecomponents then self.wallupdatecomponents = nil WallUpdatingEnts[self.GUID] = nil end NewWallUpdatingEnts[self.GUID] = nil if self.children then for k,v in pairs(self.children) do k.parent = nil k:Remove() end end if self.OnRemoveEntity then self:OnRemoveEntity() end self.persists = false self.entity:Retire() end
Steps to Reproduce
This is fixed by hiding the entity from searches by adding the "CLASSIFIED" tag:
function OnRemoveEntity(entityguid) PhysicsCollisionCallbacks[entityguid] = nil local ent = Ents[entityguid] if ent then if debug_entity == ent then debug_entity = nil end BrainManager:OnRemoveEntity(ent) SGManager:OnRemoveEntity(ent) ent:KillTasks() NumEnts = NumEnts - 1 Ents[entityguid] = nil --the entity is removed from Ents table but not retired yet --so we don't want to include it in FindEntities searches anymore ent:AddTag("CLASSIFIED") if UpdatingEnts[entityguid] then UpdatingEnts[entityguid] = nil num_updating_ents = num_updating_ents - 1 end if WallUpdatingEnts[entityguid] then WallUpdatingEnts[entityguid] = nil end end end
-
1
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now