From fe5cfdf4954aa86802c12862f8018ab30eb5f306 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 7 May 2015 10:28:38 -0700 Subject: [PATCH] fix crash bug when obj deleted but dangling pointer still on _pendingAdd which would not be removed during getObjectsToDelete() because backpointers had been disconnected --- libraries/physics/src/PhysicalEntitySimulation.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index bc3c5eda44..cf88af4942 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -67,6 +67,12 @@ void PhysicalEntitySimulation::removeEntityInternal(EntityItem* entity) { if (motionState) { motionState->clearEntity(); entity->setPhysicsInfo(nullptr); + + // NOTE: we must remove entity from _pendingAdds immediately because we've disconnected the backpointers between + // motionState and entity and they can't be used to look up each other. However we don't need to remove + // motionState from _pendingChanges at this time becuase it will be removed during getObjectsToDelete(). + _pendingAdds.remove(entity); + _pendingRemoves.insert(motionState); _outgoingChanges.remove(motionState); }