mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 14:37:46 +02:00
Merge pull request #7087 from AndrewMeadows/crash-fix
yet another attempt to avoid physics crashes
This commit is contained in:
commit
89b85f3a78
1 changed files with 20 additions and 16 deletions
|
@ -145,7 +145,7 @@ void PhysicsEngine::removeObjects(const VectorOfMotionStates& objects) {
|
|||
// then remove them
|
||||
for (auto object : objects) {
|
||||
btRigidBody* body = object->getRigidBody();
|
||||
assert(body);
|
||||
if (body) {
|
||||
_dynamicsWorld->removeRigidBody(body);
|
||||
|
||||
// NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it.
|
||||
|
@ -153,13 +153,15 @@ void PhysicsEngine::removeObjects(const VectorOfMotionStates& objects) {
|
|||
body->setMotionState(nullptr);
|
||||
delete body;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Same as above, but takes a Set instead of a Vector. Should only be called during teardown.
|
||||
void PhysicsEngine::removeObjects(const SetOfMotionStates& objects) {
|
||||
_contactMap.clear();
|
||||
for (auto object : objects) {
|
||||
btRigidBody* body = object->getRigidBody();
|
||||
assert(body);
|
||||
if (body) {
|
||||
_dynamicsWorld->removeRigidBody(body);
|
||||
|
||||
// NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it.
|
||||
|
@ -167,6 +169,7 @@ void PhysicsEngine::removeObjects(const SetOfMotionStates& objects) {
|
|||
body->setMotionState(nullptr);
|
||||
delete body;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsEngine::addObjects(const VectorOfMotionStates& objects) {
|
||||
|
@ -200,11 +203,12 @@ void PhysicsEngine::reinsertObject(ObjectMotionState* object) {
|
|||
// remove object from DynamicsWorld
|
||||
bumpAndPruneContacts(object);
|
||||
btRigidBody* body = object->getRigidBody();
|
||||
assert(body);
|
||||
if (body) {
|
||||
_dynamicsWorld->removeRigidBody(body);
|
||||
|
||||
// add it back
|
||||
addObjectToDynamicsWorld(object);
|
||||
}
|
||||
}
|
||||
|
||||
void PhysicsEngine::removeContacts(ObjectMotionState* motionState) {
|
||||
|
|
Loading…
Reference in a new issue