mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 15:38:00 +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,27 +145,30 @@ void PhysicsEngine::removeObjects(const VectorOfMotionStates& objects) {
|
||||||
// then remove them
|
// then remove them
|
||||||
for (auto object : objects) {
|
for (auto object : objects) {
|
||||||
btRigidBody* body = object->getRigidBody();
|
btRigidBody* body = object->getRigidBody();
|
||||||
assert(body);
|
if (body) {
|
||||||
_dynamicsWorld->removeRigidBody(body);
|
_dynamicsWorld->removeRigidBody(body);
|
||||||
|
|
||||||
// NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it.
|
// NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it.
|
||||||
object->setRigidBody(nullptr);
|
object->setRigidBody(nullptr);
|
||||||
body->setMotionState(nullptr);
|
body->setMotionState(nullptr);
|
||||||
delete body;
|
delete body;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same as above, but takes a Set instead of a Vector. Should only be called during teardown.
|
// Same as above, but takes a Set instead of a Vector. Should only be called during teardown.
|
||||||
void PhysicsEngine::removeObjects(const SetOfMotionStates& objects) {
|
void PhysicsEngine::removeObjects(const SetOfMotionStates& objects) {
|
||||||
|
_contactMap.clear();
|
||||||
for (auto object : objects) {
|
for (auto object : objects) {
|
||||||
btRigidBody* body = object->getRigidBody();
|
btRigidBody* body = object->getRigidBody();
|
||||||
assert(body);
|
if (body) {
|
||||||
_dynamicsWorld->removeRigidBody(body);
|
_dynamicsWorld->removeRigidBody(body);
|
||||||
|
|
||||||
// NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it.
|
// NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it.
|
||||||
object->setRigidBody(nullptr);
|
object->setRigidBody(nullptr);
|
||||||
body->setMotionState(nullptr);
|
body->setMotionState(nullptr);
|
||||||
delete body;
|
delete body;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,11 +203,12 @@ void PhysicsEngine::reinsertObject(ObjectMotionState* object) {
|
||||||
// remove object from DynamicsWorld
|
// remove object from DynamicsWorld
|
||||||
bumpAndPruneContacts(object);
|
bumpAndPruneContacts(object);
|
||||||
btRigidBody* body = object->getRigidBody();
|
btRigidBody* body = object->getRigidBody();
|
||||||
assert(body);
|
if (body) {
|
||||||
_dynamicsWorld->removeRigidBody(body);
|
_dynamicsWorld->removeRigidBody(body);
|
||||||
|
|
||||||
// add it back
|
// add it back
|
||||||
addObjectToDynamicsWorld(object);
|
addObjectToDynamicsWorld(object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsEngine::removeContacts(ObjectMotionState* motionState) {
|
void PhysicsEngine::removeContacts(ObjectMotionState* motionState) {
|
||||||
|
|
Loading…
Reference in a new issue