From c6cde2d412833ea0e6bdaf06c54c608d8572843a Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 5 Nov 2018 11:13:32 -0800 Subject: [PATCH 1/3] don't assign null Shape to RigidBody already in physics simulation --- libraries/physics/src/ObjectMotionState.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index c814140930..acfb0c9236 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -305,15 +305,16 @@ bool ObjectMotionState::handleHardAndEasyChanges(uint32_t& flags, PhysicsEngine* } return true; } - } - if (_shape == newShape) { - // the shape didn't actually change, so we clear the DIRTY_SHAPE flag - flags &= ~Simulation::DIRTY_SHAPE; - // and clear the reference we just created - getShapeManager()->releaseShape(_shape); } else { - _body->setCollisionShape(const_cast(newShape)); - setShape(newShape); + if (_shape == newShape) { + // the shape didn't actually change, so we clear the DIRTY_SHAPE flag + flags &= ~Simulation::DIRTY_SHAPE; + // and clear the reference we just created + getShapeManager()->releaseShape(_shape); + } else { + _body->setCollisionShape(const_cast(newShape)); + setShape(newShape); + } } } if (flags & EASY_DIRTY_PHYSICS_FLAGS) { From 9e7b68feadd572f863bf1e03e5a8e1804b1ec11b Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 5 Nov 2018 11:14:32 -0800 Subject: [PATCH 2/3] find and remove dangling pointers from _activeStaticBodies on remove --- libraries/physics/src/PhysicsEngine.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 8343919ae1..9e75dec475 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -289,6 +289,12 @@ void PhysicsEngine::processTransaction(PhysicsEngine::Transaction& transaction) bumpAndPruneContacts(object); btRigidBody* body = object->getRigidBody(); if (body) { + if (_activeStaticBodies.size() > 0) { + std::set::iterator itr = _activeStaticBodies.find(body); + if (itr != _activeStaticBodies.end()) { + _activeStaticBodies.erase(itr); + } + } removeDynamicsForBody(body); _dynamicsWorld->removeRigidBody(body); From 228847b5075b2d0ff1997bbc87f3eaa86f752ec1 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 5 Nov 2018 11:44:58 -0800 Subject: [PATCH 3/3] only look in _activeStaticBodies when body is static --- libraries/physics/src/PhysicsEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 9e75dec475..bf6e2463e5 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -289,7 +289,7 @@ void PhysicsEngine::processTransaction(PhysicsEngine::Transaction& transaction) bumpAndPruneContacts(object); btRigidBody* body = object->getRigidBody(); if (body) { - if (_activeStaticBodies.size() > 0) { + if (body->isStaticObject() && _activeStaticBodies.size() > 0) { std::set::iterator itr = _activeStaticBodies.find(body); if (itr != _activeStaticBodies.end()) { _activeStaticBodies.erase(itr);