be more careful about fixing up entities which arrived before their parents

This commit is contained in:
Seth Alves 2017-05-19 12:13:43 -07:00
parent 735e4b7d05
commit 936d0e2d50

View file

@ -122,7 +122,7 @@ void EntityTree::postAddEntity(EntityItemPointer entity) {
_simulation->addEntity(entity);
}
if (!entity->isParentIDValid()) {
if (!entity->getParentID().isNull()) {
QWriteLocker locker(&_missingParentLock);
_missingParent.append(entity);
}
@ -1212,28 +1212,15 @@ void EntityTree::entityChanged(EntityItemPointer entity) {
void EntityTree::fixupMissingParents() {
MovingEntitiesOperator moveOperator(getThisPointer());
QList<EntityItemPointer> missingParents;
{
QWriteLocker locker(&_missingParentLock);
QMutableVectorIterator<EntityItemWeakPointer> iter(_missingParent);
while (iter.hasNext()) {
EntityItemWeakPointer entityWP = iter.next();
EntityItemPointer entity = entityWP.lock();
if (entity) {
if (entity->isParentIDValid()) {
iter.remove();
} else {
missingParents.append(entity);
}
} else {
// entity was deleted before we found its parent.
if (!entity) {
// entity was deleted before we found its parent
iter.remove();
}
}
}
for (EntityItemPointer entity : missingParents) {
if (entity) {
bool queryAACubeSuccess;
AACube newCube = entity->getQueryAACube(queryAACubeSuccess);
if (queryAACubeSuccess) {
@ -1247,6 +1234,7 @@ void EntityTree::fixupMissingParents() {
bool doMove = false;
if (entity->isParentIDValid()) {
iter.remove(); // this entity is all hooked up; we can remove it from the list
// this entity's parent was previously not known, and now is. Update its location in the EntityTree...
doMove = true;
// the bounds on the render-item may need to be updated, the rigid body in the physics engine may
@ -1273,6 +1261,7 @@ void EntityTree::fixupMissingParents() {
}
_childrenOfAvatars[entity->getParentID()] += entity->getEntityItemID();
doMove = true;
iter.remove(); // and pull it out of the list
}
if (queryAACubeSuccess && doMove) {
@ -1280,7 +1269,6 @@ void EntityTree::fixupMissingParents() {
entity->markAncestorMissing(false);
}
}
}
if (moveOperator.hasMovingEntities()) {
PerformanceTimer perfTimer("recurseTreeWithOperator");