1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-05 19:45:33 +00:00

Guard the Bullet drawing method with a read lock on the

btCollisionWorld. It closes a race on the collision shapes coordinates.
This commit is contained in:
fredzio 2021-03-26 23:45:56 +01:00
parent dbd6e3bfee
commit b58244ac26
3 changed files with 19 additions and 4 deletions

View file

@ -9,6 +9,7 @@
#include "components/settings/settings.hpp" #include "components/settings/settings.hpp"
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"
#include "../mwmechanics/movement.hpp" #include "../mwmechanics/movement.hpp"
#include "../mwrender/bulletdebugdraw.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/player.hpp" #include "../mwworld/player.hpp"
@ -137,11 +138,12 @@ namespace
namespace MWPhysics namespace MWPhysics
{ {
PhysicsTaskScheduler::PhysicsTaskScheduler(float physicsDt, btCollisionWorld *collisionWorld) PhysicsTaskScheduler::PhysicsTaskScheduler(float physicsDt, btCollisionWorld *collisionWorld, MWRender::DebugDrawer* debugDrawer)
: mDefaultPhysicsDt(physicsDt) : mDefaultPhysicsDt(physicsDt)
, mPhysicsDt(physicsDt) , mPhysicsDt(physicsDt)
, mTimeAccum(0.f) , mTimeAccum(0.f)
, mCollisionWorld(collisionWorld) , mCollisionWorld(collisionWorld)
, mDebugDrawer(debugDrawer)
, mNumJobs(0) , mNumJobs(0)
, mRemainingSteps(0) , mRemainingSteps(0)
, mLOSCacheExpiry(Settings::Manager::getInt("lineofsight keep inactive cache", "Physics")) , mLOSCacheExpiry(Settings::Manager::getInt("lineofsight keep inactive cache", "Physics"))
@ -626,4 +628,10 @@ namespace MWPhysics
mTimeBegin = mTimer->tick(); mTimeBegin = mTimer->tick();
mFrameNumber = frameNumber; mFrameNumber = frameNumber;
} }
void PhysicsTaskScheduler::debugDraw()
{
std::shared_lock lock(mCollisionWorldMutex);
mDebugDrawer->step();
}
} }

View file

@ -20,12 +20,17 @@ namespace Misc
class Barrier; class Barrier;
} }
namespace MWRender
{
class DebugDrawer;
}
namespace MWPhysics namespace MWPhysics
{ {
class PhysicsTaskScheduler class PhysicsTaskScheduler
{ {
public: public:
PhysicsTaskScheduler(float physicsDt, btCollisionWorld* collisionWorld); PhysicsTaskScheduler(float physicsDt, btCollisionWorld* collisionWorld, MWRender::DebugDrawer* debugDrawer);
~PhysicsTaskScheduler(); ~PhysicsTaskScheduler();
/// @brief move actors taking into account desired movements and collisions /// @brief move actors taking into account desired movements and collisions
@ -49,6 +54,7 @@ namespace MWPhysics
void removeCollisionObject(btCollisionObject* collisionObject); void removeCollisionObject(btCollisionObject* collisionObject);
void updateSingleAabb(std::weak_ptr<PtrHolder> ptr, bool immediate=false); void updateSingleAabb(std::weak_ptr<PtrHolder> ptr, bool immediate=false);
bool getLineOfSight(const std::weak_ptr<Actor>& actor1, const std::weak_ptr<Actor>& actor2); bool getLineOfSight(const std::weak_ptr<Actor>& actor1, const std::weak_ptr<Actor>& actor2);
void debugDraw();
private: private:
void syncComputation(); void syncComputation();
@ -68,6 +74,7 @@ namespace MWPhysics
float mPhysicsDt; float mPhysicsDt;
float mTimeAccum; float mTimeAccum;
btCollisionWorld* mCollisionWorld; btCollisionWorld* mCollisionWorld;
MWRender::DebugDrawer* mDebugDrawer;
std::vector<LOSRequest> mLOSCache; std::vector<LOSRequest> mLOSCache;
std::set<std::weak_ptr<PtrHolder>, std::owner_less<std::weak_ptr<PtrHolder>>> mUpdateAabb; std::set<std::weak_ptr<PtrHolder>, std::owner_less<std::weak_ptr<PtrHolder>>> mUpdateAabb;

View file

@ -97,8 +97,8 @@ namespace MWPhysics
} }
} }
mTaskScheduler = std::make_unique<PhysicsTaskScheduler>(mPhysicsDt, mCollisionWorld.get());
mDebugDrawer = std::make_unique<MWRender::DebugDrawer>(mParentNode, mCollisionWorld.get(), mDebugDrawEnabled); mDebugDrawer = std::make_unique<MWRender::DebugDrawer>(mParentNode, mCollisionWorld.get(), mDebugDrawEnabled);
mTaskScheduler = std::make_unique<PhysicsTaskScheduler>(mPhysicsDt, mCollisionWorld.get(), mDebugDrawer.get());
} }
PhysicsSystem::~PhysicsSystem() PhysicsSystem::~PhysicsSystem()
@ -827,7 +827,7 @@ namespace MWPhysics
void PhysicsSystem::debugDraw() void PhysicsSystem::debugDraw()
{ {
if (mDebugDrawEnabled) if (mDebugDrawEnabled)
mDebugDrawer->step(); mTaskScheduler->debugDraw();
} }
bool PhysicsSystem::isActorStandingOn(const MWWorld::Ptr &actor, const MWWorld::ConstPtr &object) const bool PhysicsSystem::isActorStandingOn(const MWWorld::Ptr &actor, const MWWorld::ConstPtr &object) const