Merge pull request #1160 from Aussiemon/actorupdatecollision

[Do not merge yet] Added check before attempting to remove actor's collision object
coverity_scan^2
scrawl 8 years ago committed by GitHub
commit 913a8fe1bd

@ -47,7 +47,7 @@ Actor::Actor(const MWWorld::Ptr& ptr, osg::ref_ptr<const Resource::BulletShape>
updateScale(); updateScale();
updatePosition(); updatePosition();
updateCollisionMask(); addCollisionMask(getCollisionMask());
} }
Actor::~Actor() Actor::~Actor()
@ -70,15 +70,26 @@ void Actor::enableCollisionBody(bool collision)
} }
} }
void Actor::addCollisionMask(int collisionMask)
{
mCollisionWorld->addCollisionObject(mCollisionObject.get(), CollisionType_Actor, collisionMask);
}
void Actor::updateCollisionMask() void Actor::updateCollisionMask()
{ {
mCollisionWorld->removeCollisionObject(mCollisionObject.get()); mCollisionWorld->removeCollisionObject(mCollisionObject.get());
addCollisionMask(getCollisionMask());
}
int Actor::getCollisionMask()
{
int collisionMask = CollisionType_World | CollisionType_HeightMap; int collisionMask = CollisionType_World | CollisionType_HeightMap;
if (mExternalCollisionMode) if (mExternalCollisionMode)
collisionMask |= CollisionType_Actor | CollisionType_Projectile | CollisionType_Door; collisionMask |= CollisionType_Actor | CollisionType_Projectile | CollisionType_Door;
if (mCanWaterWalk) if (mCanWaterWalk)
collisionMask |= CollisionType_Water; collisionMask |= CollisionType_Water;
mCollisionWorld->addCollisionObject(mCollisionObject.get(), CollisionType_Actor, collisionMask); return collisionMask;
} }
void Actor::updatePosition() void Actor::updatePosition()

@ -139,6 +139,8 @@ namespace MWPhysics
private: private:
/// Removes then re-adds the collision object to the dynamics world /// Removes then re-adds the collision object to the dynamics world
void updateCollisionMask(); void updateCollisionMask();
void addCollisionMask(int collisionMask);
int getCollisionMask();
bool mCanWaterWalk; bool mCanWaterWalk;
bool mWalkingOnWater; bool mWalkingOnWater;

@ -1467,7 +1467,10 @@ namespace MWPhysics
} }
if (!mWaterEnabled) if (!mWaterEnabled)
{
mWaterCollisionObject.reset();
return; return;
}
mWaterCollisionObject.reset(new btCollisionObject()); mWaterCollisionObject.reset(new btCollisionObject());
mWaterCollisionShape.reset(new btStaticPlaneShape(btVector3(0,0,1), mWaterHeight)); mWaterCollisionShape.reset(new btStaticPlaneShape(btVector3(0,0,1), mWaterHeight));

Loading…
Cancel
Save