From e30dfb13d3bb1771ebd5b963e1d07fa6ee27a503 Mon Sep 17 00:00:00 2001 From: Aussiemon Date: Wed, 14 Dec 2016 19:05:30 -0700 Subject: [PATCH 1/3] Added check before attempting to remove actor's collision object from world --- apps/openmw/mwphysics/actor.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwphysics/actor.cpp b/apps/openmw/mwphysics/actor.cpp index 61022da28..dacffe22c 100644 --- a/apps/openmw/mwphysics/actor.cpp +++ b/apps/openmw/mwphysics/actor.cpp @@ -72,7 +72,10 @@ void Actor::enableCollisionBody(bool collision) void Actor::updateCollisionMask() { - mCollisionWorld->removeCollisionObject(mCollisionObject.get()); + if (mCollisionObject.get()->getWorldArrayIndex() >= 0) + { + mCollisionWorld->removeCollisionObject(mCollisionObject.get()); + } int collisionMask = CollisionType_World | CollisionType_HeightMap; if (mExternalCollisionMode) collisionMask |= CollisionType_Actor | CollisionType_Projectile | CollisionType_Door; From 7c2a088b34cf9acff43586d1c6d303f57bb82927 Mon Sep 17 00:00:00 2001 From: Aussiemon Date: Wed, 14 Dec 2016 20:13:23 -0700 Subject: [PATCH 2/3] Added check before removing water collision object from world --- apps/openmw/mwphysics/physicssystem.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index 1a97fc6ff..1985dba18 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -1463,7 +1463,10 @@ namespace MWPhysics { if (mWaterCollisionObject.get()) { - mCollisionWorld->removeCollisionObject(mWaterCollisionObject.get()); + if (mWaterCollisionObject.get()->getWorldArrayIndex() >= 0) + { + mCollisionWorld->removeCollisionObject(mWaterCollisionObject.get()); + } } if (!mWaterEnabled) From b794aa7c2f3c0621c8e3de7029efe4dcc1750909 Mon Sep 17 00:00:00 2001 From: Aussiemon Date: Fri, 16 Dec 2016 12:22:07 -0700 Subject: [PATCH 3/3] Helper methods for updateCollisionMask(), prevent water collision being removed twice, remove Bullet 2.8.5 methods --- apps/openmw/mwphysics/actor.cpp | 20 ++++++++++++++------ apps/openmw/mwphysics/actor.hpp | 2 ++ apps/openmw/mwphysics/physicssystem.cpp | 8 ++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwphysics/actor.cpp b/apps/openmw/mwphysics/actor.cpp index dacffe22c..9be34495e 100644 --- a/apps/openmw/mwphysics/actor.cpp +++ b/apps/openmw/mwphysics/actor.cpp @@ -47,7 +47,7 @@ Actor::Actor(const MWWorld::Ptr& ptr, osg::ref_ptr updateScale(); updatePosition(); - updateCollisionMask(); + addCollisionMask(getCollisionMask()); } Actor::~Actor() @@ -70,18 +70,26 @@ void Actor::enableCollisionBody(bool collision) } } +void Actor::addCollisionMask(int collisionMask) +{ + mCollisionWorld->addCollisionObject(mCollisionObject.get(), CollisionType_Actor, collisionMask); +} + void Actor::updateCollisionMask() { - if (mCollisionObject.get()->getWorldArrayIndex() >= 0) - { - mCollisionWorld->removeCollisionObject(mCollisionObject.get()); - } + mCollisionWorld->removeCollisionObject(mCollisionObject.get()); + addCollisionMask(getCollisionMask()); +} + +int Actor::getCollisionMask() +{ int collisionMask = CollisionType_World | CollisionType_HeightMap; if (mExternalCollisionMode) collisionMask |= CollisionType_Actor | CollisionType_Projectile | CollisionType_Door; if (mCanWaterWalk) collisionMask |= CollisionType_Water; - mCollisionWorld->addCollisionObject(mCollisionObject.get(), CollisionType_Actor, collisionMask); + return collisionMask; + } void Actor::updatePosition() diff --git a/apps/openmw/mwphysics/actor.hpp b/apps/openmw/mwphysics/actor.hpp index b238547e1..a0bf5bfc0 100644 --- a/apps/openmw/mwphysics/actor.hpp +++ b/apps/openmw/mwphysics/actor.hpp @@ -139,6 +139,8 @@ namespace MWPhysics private: /// Removes then re-adds the collision object to the dynamics world void updateCollisionMask(); + void addCollisionMask(int collisionMask); + int getCollisionMask(); bool mCanWaterWalk; bool mWalkingOnWater; diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index 1985dba18..f94ee14b6 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -1463,14 +1463,14 @@ namespace MWPhysics { if (mWaterCollisionObject.get()) { - if (mWaterCollisionObject.get()->getWorldArrayIndex() >= 0) - { - mCollisionWorld->removeCollisionObject(mWaterCollisionObject.get()); - } + mCollisionWorld->removeCollisionObject(mWaterCollisionObject.get()); } if (!mWaterEnabled) + { + mWaterCollisionObject.reset(); return; + } mWaterCollisionObject.reset(new btCollisionObject()); mWaterCollisionShape.reset(new btStaticPlaneShape(btVector3(0,0,1), mWaterHeight));