1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-25 21:41:04 +00:00

Limit max bullet supported threads by BT_MAX_THREAD_COUNT - 1

There is a check and assert for number of threads >= BT_MAX_THREAD_COUNT.
btDbvtBroadphase::m_rayTestStacks::size may return BT_MAX_THREAD_COUNT which
triggers the assert.
This commit is contained in:
elsid 2023-03-04 02:08:42 +01:00
parent 88567cd363
commit 949b9191a5
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

View File

@ -10,6 +10,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>
@ -305,10 +306,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()
@ -330,8 +332,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: "