Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <mont29>2020-07-29 18:36:27 +0300
committerBastien Montagne <bastien@blender.org>2020-07-29 18:36:46 +0300
commit4e6975ffd6656fb9abbaa577fef0815666c6c808 (patch)
tree9906dc88494655373167a92d90e2904f051869f2 /source/blender/blenkernel/intern/mesh_runtime.c
parent54a2fcc0f331b8971e8a105382e9a8f67e1859e3 (diff)
Fix T78285: Invalid thread safety in shrinkwrap modifier code.
This uses mesh's runtime mutex for both `BKE_mesh_runtime_looptri_ensure` (was using its own global RW mutex before), and `BKE_mesh_wrapper_ensure_mdata` (was not protected at all before). This is more like a band-aid than a proper fix, as mentioned in the report proper fix would be for the modifier to request those data (the relevant BVHTree, which would implicitely also call the tow others) through flags, just like it does for regular CDData layers. But this is a much bigger refactor to be done outside of bugfix scope. Reviewed By: sergey Maniphest Tasks: T78285 Differential Revision: https://developer.blender.org/D8415
Diffstat (limited to 'source/blender/blenkernel/intern/mesh_runtime.c')
-rw-r--r--source/blender/blenkernel/intern/mesh_runtime.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/source/blender/blenkernel/intern/mesh_runtime.c b/source/blender/blenkernel/intern/mesh_runtime.c
index 932423bc445..b9eb3876dde 100644
--- a/source/blender/blenkernel/intern/mesh_runtime.c
+++ b/source/blender/blenkernel/intern/mesh_runtime.c
@@ -43,8 +43,6 @@
/** \name Mesh Runtime Struct Utils
* \{ */
-static ThreadRWMutex loops_cache_lock = PTHREAD_RWLOCK_INITIALIZER;
-
/**
* Default values defined at read time.
*/
@@ -159,23 +157,21 @@ const MLoopTri *BKE_mesh_runtime_looptri_ensure(Mesh *mesh)
{
MLoopTri *looptri;
- BLI_rw_mutex_lock(&loops_cache_lock, THREAD_LOCK_READ);
+ ThreadMutex *mesh_eval_mutex = (ThreadMutex *)mesh->runtime.eval_mutex;
+ BLI_mutex_lock(mesh_eval_mutex);
+
looptri = mesh->runtime.looptris.array;
- BLI_rw_mutex_unlock(&loops_cache_lock);
if (looptri != NULL) {
BLI_assert(BKE_mesh_runtime_looptri_len(mesh) == mesh->runtime.looptris.len);
}
else {
- BLI_rw_mutex_lock(&loops_cache_lock, THREAD_LOCK_WRITE);
- /* We need to ensure array is still NULL inside mutex-protected code,
- * some other thread might have already recomputed those looptris. */
- if (mesh->runtime.looptris.array == NULL) {
- BKE_mesh_runtime_looptri_recalc(mesh);
- }
+ BKE_mesh_runtime_looptri_recalc(mesh);
looptri = mesh->runtime.looptris.array;
- BLI_rw_mutex_unlock(&loops_cache_lock);
}
+
+ BLI_mutex_unlock(mesh_eval_mutex);
+
return looptri;
}