diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 97a24e97f1..32e725388c 100755 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -549,28 +549,6 @@ void AvatarManager::removeDeadAvatarEntities(const SetOfEntities& deadEntities) } } -/* ADEBUG: I don't think the code below is necessary because any dead entities will have already been removed from tree and simulation - if (entityTree && entity->isMyAvatarEntity()) { - entityTree->withWriteLock([&] { - // We only need to delete the direct children (rather than the descendants) because - // when the child is deleted, it will take care of its own children. If the child - // is also an avatar-entity, we'll end up back here. If it's not, the entity-server - // will take care of it in the usual way. - entity->forEachChild([&](SpatiallyNestablePointer child) { - EntityItemPointer childEntity = std::dynamic_pointer_cast(child); - if (childEntity) { - entityTree->deleteEntity(childEntity->getID(), true, true); - if (avatar) { - avatar->clearAvatarEntity(childEntity->getID(), REQUIRES_REMOVAL_FROM_TREE); - } - } - }); - }); - } - } -} -*/ - void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar, KillAvatarReason removalReason) { auto avatar = std::static_pointer_cast(removedAvatar); AvatarHashMap::handleRemovedAvatar(avatar, removalReason); diff --git a/libraries/entities/src/EntitySimulation.cpp b/libraries/entities/src/EntitySimulation.cpp index 48de811be5..5576f21cc5 100644 --- a/libraries/entities/src/EntitySimulation.cpp +++ b/libraries/entities/src/EntitySimulation.cpp @@ -43,7 +43,7 @@ void EntitySimulation::updateEntities() { } void EntitySimulation::removeEntityFromInternalLists(EntityItemPointer entity) { - // remove from all internal lists except _deadEntities + // remove from all internal lists except _deadEntitiesToRemoveFromTree _entitiesToSort.remove(entity); _simpleKinematicEntities.remove(entity); _allEntities.remove(entity); @@ -59,7 +59,7 @@ void EntitySimulation::prepareEntityForDelete(EntityItemPointer entity) { QMutexLocker lock(&_mutex); removeEntityFromInternalLists(entity); if (entity->getElement()) { - _deadEntities.insert(entity); + _deadEntitiesToRemoveFromTree.insert(entity); _entityTree->cleanupCloneIDs(entity->getEntityItemID()); } } @@ -217,7 +217,7 @@ void EntitySimulation::clearEntities() { _simpleKinematicEntities.clear(); _changedEntities.clear(); _allEntities.clear(); - _deadEntities.clear(); + _deadEntitiesToRemoveFromTree.clear(); _entitiesToUpdate.clear(); _mortalEntities.clear(); _nextExpiry = std::numeric_limits::max(); @@ -257,18 +257,21 @@ void EntitySimulation::moveSimpleKinematics(uint64_t now) { } void EntitySimulation::processDeadEntities() { - if (_deadEntities.empty()) { + if (_deadEntitiesToRemoveFromTree.empty()) { return; } SetOfEntities entitiesToDeleteImmediately; - SetOfEntities dummyList; // ignore this list: it will be empty - foreach (auto entity, _deadEntities) { - QUuid nullSessionID; + // NOTE: dummyList will be empty because this base-class implementation is only used server-side + // for which ATM we only process domain-entities, and since we are passing nullSessionID for authorization + // EntityItem::collectChildrenForDelete() will not collect domain-entities into this side list. + SetOfEntities dummyList; + QUuid nullSessionID; + foreach (auto entity, _deadEntitiesToRemoveFromTree) { entitiesToDeleteImmediately.insert(entity); entity->collectChildrenForDelete(entitiesToDeleteImmediately, dummyList, nullSessionID); } if (_entityTree) { _entityTree->deleteEntitiesByPointer(entitiesToDeleteImmediately); } - _deadEntities.clear(); + _deadEntitiesToRemoveFromTree.clear(); } diff --git a/libraries/entities/src/EntitySimulation.h b/libraries/entities/src/EntitySimulation.h index 6c32a7526f..646e5a0f67 100644 --- a/libraries/entities/src/EntitySimulation.h +++ b/libraries/entities/src/EntitySimulation.h @@ -94,7 +94,7 @@ protected: SetOfEntities _entitiesToSort; // entities moved by simulation (and might need resort in EntityTree) SetOfEntities _simpleKinematicEntities; // entities undergoing non-colliding kinematic motion - SetOfEntities _deadEntities; // dead entities that might still be in the _entityTree + SetOfEntities _deadEntitiesToRemoveFromTree; private: void moveSimpleKinematics(); diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index a7f66929ed..0375e1dfd9 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -69,7 +69,7 @@ void PhysicalEntitySimulation::removeEntityFromInternalLists(EntityItemPointer e _entitiesToRemoveFromPhysics.insert(entity); } if (entity->isDead() && entity->getElement()) { - _deadEntities.insert(entity); + _deadEntitiesToRemoveFromTree.insert(entity); } if (entity->isAvatarEntity()) { _deadAvatarEntities.insert(entity); @@ -171,7 +171,7 @@ void PhysicalEntitySimulation::processChangedEntity(const EntityItemPointer& ent } void PhysicalEntitySimulation::processDeadEntities() { - if (_deadEntities.empty()) { + if (_deadEntitiesToRemoveFromTree.empty()) { return; } PROFILE_RANGE(simulation_physics, "Deletes"); @@ -179,7 +179,7 @@ void PhysicalEntitySimulation::processDeadEntities() { SetOfEntities domainEntities; QUuid sessionID = Physics::getSessionUUID(); QMutexLocker lock(&_mutex); - for (auto entity : _deadEntities) { + for (auto entity : _deadEntitiesToRemoveFromTree) { EntityMotionState* motionState = static_cast(entity->getPhysicsInfo()); if (motionState) { _entitiesToRemoveFromPhysics.insert(entity); @@ -191,7 +191,7 @@ void PhysicalEntitySimulation::processDeadEntities() { entity->collectChildrenForDelete(entitiesToDeleteImmediately, domainEntities, sessionID); } } - _deadEntities.clear(); + _deadEntitiesToRemoveFromTree.clear(); // interface-client can't delete domainEntities outright, they must roundtrip through the entity-server for (auto entity : domainEntities) { diff --git a/libraries/physics/src/PhysicalEntitySimulation.h b/libraries/physics/src/PhysicalEntitySimulation.h index 869ad1f108..a3bd60b96e 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.h +++ b/libraries/physics/src/PhysicalEntitySimulation.h @@ -124,7 +124,7 @@ private: VectorOfEntityMotionStates _owned; VectorOfEntityMotionStates _bids; - SetOfEntities _deadAvatarEntities; + SetOfEntities _deadAvatarEntities; // to remove from Avatar's lists std::vector _entitiesToDeleteLater; QList _dynamicsToAdd;