Skip to content

Commit

Permalink
Merge pull request #73628 from lawnjelly/bvh_mutex_fix
Browse files Browse the repository at this point in the history
BVH - fix lockguards for multithread mode
  • Loading branch information
akien-mga authored Feb 20, 2023
2 parents dfdda96 + f42a837 commit 9c960a8
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions core/math/bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#include "core/os/mutex.h"

#define BVHTREE_CLASS BVH_Tree<T, NUM_TREES, 2, MAX_ITEMS, USER_PAIR_TEST_FUNCTION, USER_CULL_TEST_FUNCTION, USE_PAIRS, BOUNDS, POINT>
#define BVH_LOCKED_FUNCTION BVHLockedFunction(&_mutex, BVH_THREAD_SAFE &&_thread_safe);
#define BVH_LOCKED_FUNCTION BVHLockedFunction _lock_guard(&_mutex, BVH_THREAD_SAFE &&_thread_safe);

template <class T, int NUM_TREES = 1, bool USE_PAIRS = false, int MAX_ITEMS = 32, class USER_PAIR_TEST_FUNCTION = BVH_DummyPairTestFunction<T>, class USER_CULL_TEST_FUNCTION = BVH_DummyCullTestFunction<T>, class BOUNDS = AABB, class POINT = Vector3, bool BVH_THREAD_SAFE = true>
class BVH_Manager {
Expand Down Expand Up @@ -779,11 +779,7 @@ class BVH_Manager {
// will be compiled out if not set in template
if (p_thread_safe) {
_mutex = p_mutex;

if (!_mutex->try_lock()) {
WARN_PRINT("Info : multithread BVH access detected (benign)");
_mutex->lock();
}
_mutex->lock();

} else {
_mutex = nullptr;
Expand Down

0 comments on commit 9c960a8

Please sign in to comment.