mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 19:41:20 +02:00
Merge pull request #4234 from AndrewMeadows/bispinor
fix physics crash on disconnect from domain-server
This commit is contained in:
commit
d76ede624c
2 changed files with 13 additions and 8 deletions
|
@ -86,7 +86,7 @@ void PhysicsEngine::removeEntityInternal(EntityItem* entity) {
|
||||||
if (physicsInfo) {
|
if (physicsInfo) {
|
||||||
EntityMotionState* motionState = static_cast<EntityMotionState*>(physicsInfo);
|
EntityMotionState* motionState = static_cast<EntityMotionState*>(physicsInfo);
|
||||||
if (motionState->getRigidBody()) {
|
if (motionState->getRigidBody()) {
|
||||||
removeObject(motionState);
|
removeObjectFromBullet(motionState);
|
||||||
} else {
|
} else {
|
||||||
// only need to hunt in this list when there is no RigidBody
|
// only need to hunt in this list when there is no RigidBody
|
||||||
_nonPhysicalKinematicObjects.remove(motionState);
|
_nonPhysicalKinematicObjects.remove(motionState);
|
||||||
|
@ -130,7 +130,7 @@ void PhysicsEngine::clearEntitiesInternal() {
|
||||||
// For now we assume this would only be called on shutdown in which case we can just let the memory get lost.
|
// For now we assume this would only be called on shutdown in which case we can just let the memory get lost.
|
||||||
QSet<EntityMotionState*>::const_iterator stateItr = _entityMotionStates.begin();
|
QSet<EntityMotionState*>::const_iterator stateItr = _entityMotionStates.begin();
|
||||||
for (stateItr = _entityMotionStates.begin(); stateItr != _entityMotionStates.end(); ++stateItr) {
|
for (stateItr = _entityMotionStates.begin(); stateItr != _entityMotionStates.end(); ++stateItr) {
|
||||||
removeObject(*stateItr);
|
removeObjectFromBullet(*stateItr);
|
||||||
delete (*stateItr);
|
delete (*stateItr);
|
||||||
}
|
}
|
||||||
_entityMotionStates.clear();
|
_entityMotionStates.clear();
|
||||||
|
@ -211,6 +211,9 @@ void PhysicsEngine::relayIncomingChangesToSimulation() {
|
||||||
if (removeMotionState) {
|
if (removeMotionState) {
|
||||||
// if we get here then there is no need to keep this motionState around (no physics or kinematics)
|
// if we get here then there is no need to keep this motionState around (no physics or kinematics)
|
||||||
_outgoingPackets.remove(motionState);
|
_outgoingPackets.remove(motionState);
|
||||||
|
if (motionState->getType() == MOTION_STATE_TYPE_ENTITY) {
|
||||||
|
_entityMotionStates.remove(static_cast<EntityMotionState*>(motionState));
|
||||||
|
}
|
||||||
// NOTE: motionState will clean up its own backpointers in the Object
|
// NOTE: motionState will clean up its own backpointers in the Object
|
||||||
delete motionState;
|
delete motionState;
|
||||||
continue;
|
continue;
|
||||||
|
@ -455,7 +458,7 @@ void PhysicsEngine::addObject(const ShapeInfo& shapeInfo, btCollisionShape* shap
|
||||||
_dynamicsWorld->addRigidBody(body);
|
_dynamicsWorld->addRigidBody(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsEngine::removeObject(ObjectMotionState* motionState) {
|
void PhysicsEngine::removeObjectFromBullet(ObjectMotionState* motionState) {
|
||||||
assert(motionState);
|
assert(motionState);
|
||||||
btRigidBody* body = motionState->getRigidBody();
|
btRigidBody* body = motionState->getRigidBody();
|
||||||
if (body) {
|
if (body) {
|
||||||
|
@ -464,8 +467,9 @@ void PhysicsEngine::removeObject(ObjectMotionState* motionState) {
|
||||||
ShapeInfoUtil::collectInfoFromShape(shape, shapeInfo);
|
ShapeInfoUtil::collectInfoFromShape(shape, shapeInfo);
|
||||||
_dynamicsWorld->removeRigidBody(body);
|
_dynamicsWorld->removeRigidBody(body);
|
||||||
_shapeManager.releaseShape(shapeInfo);
|
_shapeManager.releaseShape(shapeInfo);
|
||||||
delete body;
|
// NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it.
|
||||||
motionState->setRigidBody(NULL);
|
motionState->setRigidBody(NULL);
|
||||||
|
delete body;
|
||||||
motionState->setKinematic(false, _numSubsteps);
|
motionState->setKinematic(false, _numSubsteps);
|
||||||
|
|
||||||
removeContacts(motionState);
|
removeContacts(motionState);
|
||||||
|
@ -492,8 +496,9 @@ bool PhysicsEngine::updateObjectHard(btRigidBody* body, ObjectMotionState* motio
|
||||||
// FAIL! we are unable to support these changes!
|
// FAIL! we are unable to support these changes!
|
||||||
_shapeManager.releaseShape(oldShape);
|
_shapeManager.releaseShape(oldShape);
|
||||||
|
|
||||||
delete body;
|
// NOTE: setRigidBody() modifies body->m_userPointer so we should clear the MotionState's body BEFORE deleting it.
|
||||||
motionState->setRigidBody(NULL);
|
motionState->setRigidBody(NULL);
|
||||||
|
delete body;
|
||||||
motionState->setKinematic(false, _numSubsteps);
|
motionState->setKinematic(false, _numSubsteps);
|
||||||
removeContacts(motionState);
|
removeContacts(motionState);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -79,13 +79,13 @@ public:
|
||||||
/// \return true if Object added
|
/// \return true if Object added
|
||||||
void addObject(const ShapeInfo& shapeInfo, btCollisionShape* shape, ObjectMotionState* motionState);
|
void addObject(const ShapeInfo& shapeInfo, btCollisionShape* shape, ObjectMotionState* motionState);
|
||||||
|
|
||||||
/// \param motionState pointer to Object's MotionState
|
|
||||||
void removeObject(ObjectMotionState* motionState);
|
|
||||||
|
|
||||||
/// process queue of changed from external sources
|
/// process queue of changed from external sources
|
||||||
void relayIncomingChangesToSimulation();
|
void relayIncomingChangesToSimulation();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/// \param motionState pointer to Object's MotionState
|
||||||
|
void removeObjectFromBullet(ObjectMotionState* motionState);
|
||||||
|
|
||||||
void removeContacts(ObjectMotionState* motionState);
|
void removeContacts(ObjectMotionState* motionState);
|
||||||
|
|
||||||
// return 'true' of update was successful
|
// return 'true' of update was successful
|
||||||
|
|
Loading…
Reference in a new issue