possible fix for entity server crash

This commit is contained in:
HifiExperiments 2020-06-08 16:58:21 -07:00
parent ade6bf24bb
commit ae8879a558
3 changed files with 8 additions and 5 deletions
assignment-client/src/entities
libraries/entities/src

View file

@ -376,9 +376,7 @@ void EntityServer::nodeAdded(SharedNodePointer node) {
void EntityServer::nodeKilled(SharedNodePointer node) {
EntityTreePointer tree = std::static_pointer_cast<EntityTree>(_tree);
tree->withWriteLock([&] {
tree->deleteDescendantsOfAvatar(node->getUUID());
});
tree->deleteDescendantsOfAvatar(node->getUUID());
tree->forgetAvatarID(node->getUUID());
OctreeServer::nodeKilled(node);
}

View file

@ -2213,6 +2213,7 @@ void EntityTree::fixupNeedsParentFixups() {
entity->postParentFixup();
} else if (getIsServer() || _avatarIDs.contains(entity->getParentID())) {
std::lock_guard<std::mutex> lock(_childrenOfAvatarsLock);
// this is a child of an avatar, which the entity server will never have
// a SpatiallyNestable object for. Add it to a list for cleanup when the avatar leaves.
if (!_childrenOfAvatars.contains(entity->getParentID())) {
@ -2241,6 +2242,7 @@ void EntityTree::fixupNeedsParentFixups() {
}
void EntityTree::deleteDescendantsOfAvatar(QUuid avatarID) {
std::lock_guard<std::mutex> lock(_childrenOfAvatarsLock);
QHash<QUuid, QSet<EntityItemID>>::const_iterator itr = _childrenOfAvatars.constFind(avatarID);
if (itr != _childrenOfAvatars.end()) {
if (!itr.value().empty()) {
@ -2259,8 +2261,10 @@ void EntityTree::deleteDescendantsOfAvatar(QUuid avatarID) {
void EntityTree::removeFromChildrenOfAvatars(EntityItemPointer entity) {
QUuid avatarID = entity->getParentID();
if (_childrenOfAvatars.contains(avatarID)) {
_childrenOfAvatars[avatarID].remove(entity->getID());
std::lock_guard<std::mutex> lock(_childrenOfAvatarsLock);
auto itr = _childrenOfAvatars.find(avatarID);
if (itr != _childrenOfAvatars.end()) {
itr.value().remove(entity->getID());
}
}

View file

@ -366,6 +366,7 @@ protected:
// we maintain a list of avatarIDs to notice when an entity is a child of one.
QSet<QUuid> _avatarIDs; // IDs of avatars connected to entity server
std::mutex _childrenOfAvatarsLock;
QHash<QUuid, QSet<EntityItemID>> _childrenOfAvatars; // which entities are children of which avatars
float _maxTmpEntityLifetime { DEFAULT_MAX_TMP_ENTITY_LIFETIME };