Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added optional thread safe version through template argument and runtime switch, that wraps access with a mutex.
Related to #48749
Related to #48790
This temporarily also adds a project setting to turn on and off use of the mutex to hopefully allow us to test whether the bug is to do with threading. The project setting is
rendering/threads/thread_safe_bvh
and defaults to off.On suggestion from @pouleyKetchoupp I've also added a
try_lock
so it should print a warning if it detects a contended situation (which would indicate that thread safety was needed).Notes
thread_safe_bvh
on my linux system. It could be that uncontended mutexes are very cheap on my system, although I can't vouch for this on other platforms.try_lock
I can't seem to get a contended lock on my system with the project from the issue (or any other). So hopefully the bug is something simpler, and we won't need to use a mutex in production. It still needs testing on windows, or by someone who can reproduce the bug.Update
The default value for the
thread_safe_bvh
is now off (if we introduce it set to on, we may never find out whether thread safety was the cause of the problems).It now operates on both the rendering BVH, and the physics BVHs for 3d and 2d. The project setting name is still the same. I'm unsure a little about having it still as
rendering/threads/thread_safe_bvh
for this reason, but there doesn't seem to be a sensible section to put it into. It may well be a temporary setting - if we discover that thread safety is required, we should probably leave it on in all cases and remove the option, and vice versa if it is not the cause of the bug.Instructions for Testers
rendering/threads/thread_safe_bvh
set to on. Please post here whether it fixes the visual bugs with eitherthread_safe_bvh
switched on or off, and especially whether you see an error / warning messageInfo : multithread BVH access detected (benign)
.