mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 15:38:00 +02:00
Merge pull request #10561 from AndrewMeadows/sanity-check-physics
fix crash in EntityMotionState::handleDeactivation()
This commit is contained in:
commit
bc2311cb35
7 changed files with 15 additions and 6 deletions
|
@ -1683,6 +1683,10 @@ Application::~Application() {
|
||||||
|
|
||||||
_physicsEngine->setCharacterController(nullptr);
|
_physicsEngine->setCharacterController(nullptr);
|
||||||
|
|
||||||
|
// the _shapeManager should have zero references
|
||||||
|
_shapeManager.collectGarbage();
|
||||||
|
assert(_shapeManager.getNumShapes() == 0);
|
||||||
|
|
||||||
// shutdown render engine
|
// shutdown render engine
|
||||||
_main3DScene = nullptr;
|
_main3DScene = nullptr;
|
||||||
_renderEngine = nullptr;
|
_renderEngine = nullptr;
|
||||||
|
@ -4490,12 +4494,13 @@ void Application::update(float deltaTime) {
|
||||||
|
|
||||||
getEntities()->getTree()->withWriteLock([&] {
|
getEntities()->getTree()->withWriteLock([&] {
|
||||||
PerformanceTimer perfTimer("handleOutgoingChanges");
|
PerformanceTimer perfTimer("handleOutgoingChanges");
|
||||||
const VectorOfMotionStates& deactivations = _physicsEngine->getDeactivatedMotionStates();
|
|
||||||
_entitySimulation->handleDeactivatedMotionStates(deactivations);
|
|
||||||
|
|
||||||
const VectorOfMotionStates& outgoingChanges = _physicsEngine->getChangedMotionStates();
|
const VectorOfMotionStates& outgoingChanges = _physicsEngine->getChangedMotionStates();
|
||||||
_entitySimulation->handleChangedMotionStates(outgoingChanges);
|
_entitySimulation->handleChangedMotionStates(outgoingChanges);
|
||||||
avatarManager->handleChangedMotionStates(outgoingChanges);
|
avatarManager->handleChangedMotionStates(outgoingChanges);
|
||||||
|
|
||||||
|
const VectorOfMotionStates& deactivations = _physicsEngine->getDeactivatedMotionStates();
|
||||||
|
_entitySimulation->handleDeactivatedMotionStates(deactivations);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!_aboutToQuit) {
|
if (!_aboutToQuit) {
|
||||||
|
|
|
@ -114,6 +114,7 @@ void EntityMotionState::handleDeactivation() {
|
||||||
|
|
||||||
// virtual
|
// virtual
|
||||||
void EntityMotionState::handleEasyChanges(uint32_t& flags) {
|
void EntityMotionState::handleEasyChanges(uint32_t& flags) {
|
||||||
|
assert(_entity);
|
||||||
assert(entityTreeIsLocked());
|
assert(entityTreeIsLocked());
|
||||||
updateServerPhysicsVariables();
|
updateServerPhysicsVariables();
|
||||||
ObjectMotionState::handleEasyChanges(flags);
|
ObjectMotionState::handleEasyChanges(flags);
|
||||||
|
@ -170,6 +171,7 @@ void EntityMotionState::handleEasyChanges(uint32_t& flags) {
|
||||||
|
|
||||||
// virtual
|
// virtual
|
||||||
bool EntityMotionState::handleHardAndEasyChanges(uint32_t& flags, PhysicsEngine* engine) {
|
bool EntityMotionState::handleHardAndEasyChanges(uint32_t& flags, PhysicsEngine* engine) {
|
||||||
|
assert(_entity);
|
||||||
updateServerPhysicsVariables();
|
updateServerPhysicsVariables();
|
||||||
return ObjectMotionState::handleHardAndEasyChanges(flags, engine);
|
return ObjectMotionState::handleHardAndEasyChanges(flags, engine);
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,6 +202,7 @@ void ObjectMotionState::setShape(const btCollisionShape* shape) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectMotionState::handleEasyChanges(uint32_t& flags) {
|
void ObjectMotionState::handleEasyChanges(uint32_t& flags) {
|
||||||
|
assert(_body && _shape);
|
||||||
if (flags & Simulation::DIRTY_POSITION) {
|
if (flags & Simulation::DIRTY_POSITION) {
|
||||||
btTransform worldTrans = _body->getWorldTransform();
|
btTransform worldTrans = _body->getWorldTransform();
|
||||||
btVector3 newPosition = glmToBullet(getObjectPosition());
|
btVector3 newPosition = glmToBullet(getObjectPosition());
|
||||||
|
@ -282,6 +283,7 @@ void ObjectMotionState::handleEasyChanges(uint32_t& flags) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ObjectMotionState::handleHardAndEasyChanges(uint32_t& flags, PhysicsEngine* engine) {
|
bool ObjectMotionState::handleHardAndEasyChanges(uint32_t& flags, PhysicsEngine* engine) {
|
||||||
|
assert(_body && _shape);
|
||||||
if (flags & Simulation::DIRTY_SHAPE) {
|
if (flags & Simulation::DIRTY_SHAPE) {
|
||||||
// make sure the new shape is valid
|
// make sure the new shape is valid
|
||||||
if (!isReadyToComputeShape()) {
|
if (!isReadyToComputeShape()) {
|
||||||
|
|
|
@ -79,7 +79,7 @@ public:
|
||||||
static ShapeManager* getShapeManager();
|
static ShapeManager* getShapeManager();
|
||||||
|
|
||||||
ObjectMotionState(const btCollisionShape* shape);
|
ObjectMotionState(const btCollisionShape* shape);
|
||||||
~ObjectMotionState();
|
virtual ~ObjectMotionState();
|
||||||
|
|
||||||
virtual void handleEasyChanges(uint32_t& flags);
|
virtual void handleEasyChanges(uint32_t& flags);
|
||||||
virtual bool handleHardAndEasyChanges(uint32_t& flags, PhysicsEngine* engine);
|
virtual bool handleHardAndEasyChanges(uint32_t& flags, PhysicsEngine* engine);
|
||||||
|
|
|
@ -130,7 +130,7 @@ void PhysicalEntitySimulation::clearEntitiesInternal() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// then remove the objects (aka MotionStates) from physics
|
// then remove the objects (aka MotionStates) from physics
|
||||||
_physicsEngine->removeObjects(_physicalObjects);
|
_physicsEngine->removeSetOfObjects(_physicalObjects);
|
||||||
|
|
||||||
// delete the MotionStates
|
// delete the MotionStates
|
||||||
// TODO: after we invert the entities/physics lib dependencies we will let EntityItem delete
|
// TODO: after we invert the entities/physics lib dependencies we will let EntityItem delete
|
||||||
|
|
|
@ -207,7 +207,7 @@ void PhysicsEngine::removeObjects(const VectorOfMotionStates& objects) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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::removeSetOfObjects(const SetOfMotionStates& objects) {
|
||||||
_contactMap.clear();
|
_contactMap.clear();
|
||||||
for (auto object : objects) {
|
for (auto object : objects) {
|
||||||
btRigidBody* body = object->getRigidBody();
|
btRigidBody* body = object->getRigidBody();
|
||||||
|
|
|
@ -53,7 +53,7 @@ public:
|
||||||
uint32_t getNumSubsteps();
|
uint32_t getNumSubsteps();
|
||||||
|
|
||||||
void removeObjects(const VectorOfMotionStates& objects);
|
void removeObjects(const VectorOfMotionStates& objects);
|
||||||
void removeObjects(const SetOfMotionStates& objects); // only called during teardown
|
void removeSetOfObjects(const SetOfMotionStates& objects); // only called during teardown
|
||||||
|
|
||||||
void addObjects(const VectorOfMotionStates& objects);
|
void addObjects(const VectorOfMotionStates& objects);
|
||||||
VectorOfMotionStates changeObjects(const VectorOfMotionStates& objects);
|
VectorOfMotionStates changeObjects(const VectorOfMotionStates& objects);
|
||||||
|
|
Loading…
Reference in a new issue