1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-31 23:45:35 +00:00

Merge branch 'limit_max_bullet_supported_threads' into 'master'

Limit max bullet supported threads by BT_MAX_THREAD_COUNT - 1

See merge request OpenMW/openmw!2797

(cherry picked from commit 31ae1cd339)

949b9191 Limit max bullet supported threads by BT_MAX_THREAD_COUNT - 1
This commit is contained in:
psi29a 2023-03-04 12:42:51 +00:00
parent a6989dcb12
commit 0fb7d93219

View file

@ -7,6 +7,7 @@
#include <BulletCollision/BroadphaseCollision/btDbvtBroadphase.h> #include <BulletCollision/BroadphaseCollision/btDbvtBroadphase.h>
#include <BulletCollision/CollisionShapes/btCollisionShape.h> #include <BulletCollision/CollisionShapes/btCollisionShape.h>
#include <LinearMath/btThreads.h>
#include <osg/Stats> #include <osg/Stats>
@ -297,10 +298,11 @@ namespace MWPhysics
{ {
namespace namespace
{ {
int getMaxBulletSupportedThreads() unsigned getMaxBulletSupportedThreads()
{ {
auto broad = std::make_unique<btDbvtBroadphase>(); auto broad = std::make_unique<btDbvtBroadphase>();
return broad->m_rayTestStacks.size(); assert(BT_MAX_THREAD_COUNT > 0);
return std::min<unsigned>(broad->m_rayTestStacks.size(), BT_MAX_THREAD_COUNT - 1);
} }
LockingPolicy detectLockingPolicy() LockingPolicy detectLockingPolicy()
@ -322,8 +324,8 @@ namespace MWPhysics
case LockingPolicy::ExclusiveLocksOnly: case LockingPolicy::ExclusiveLocksOnly:
return 1; return 1;
case LockingPolicy::AllowSharedLocks: case LockingPolicy::AllowSharedLocks:
return static_cast<unsigned>(std::clamp( return std::clamp<unsigned>(
Settings::Manager::getInt("async num threads", "Physics"), 0, getMaxBulletSupportedThreads())); Settings::Manager::getInt("async num threads", "Physics"), 0, getMaxBulletSupportedThreads());
} }
throw std::runtime_error("Unsupported LockingPolicy: " throw std::runtime_error("Unsupported LockingPolicy: "