diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-09-19 14:09:35 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-01-08 18:42:36 +0300 |
commit | 754630cee4fec23fc407876b5199c40ea892e8c3 (patch) | |
tree | 9d41b708580e37aac26cf1fc639904524f535ac7 /source/blender/blenkernel | |
parent | 00d8097510f6dedad509d4bc0162822b36932a86 (diff) |
Fix T52823: New Depsgraph - Shrinkwrap crashes blender
The issue was caused by threading conflict around looptris: it was possible
that DM will return non-NULL but non-initialized array of looptris.
Thanks Campbell for second pair of eyes!
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 58ce00f2fdb..ace79f4125b 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -94,7 +94,7 @@ static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm); #endif -static ThreadMutex loops_cache_lock = BLI_MUTEX_INITIALIZER; +static ThreadRWMutex loops_cache_lock = PTHREAD_RWLOCK_INITIALIZER; static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *ob); @@ -241,19 +241,26 @@ static int dm_getNumLoopTri(DerivedMesh *dm) static const MLoopTri *dm_getLoopTriArray(DerivedMesh *dm) { - if (dm->looptris.array) { + MLoopTri *looptri; + + BLI_rw_mutex_lock(&loops_cache_lock, THREAD_LOCK_READ); + looptri = dm->looptris.array; + BLI_rw_mutex_unlock(&loops_cache_lock); + + if (looptri != NULL) { BLI_assert(dm->getNumLoopTri(dm) == dm->looptris.num); } else { - BLI_mutex_lock(&loops_cache_lock); + 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 (dm->looptris.array == NULL) { dm->recalcLoopTri(dm); } - BLI_mutex_unlock(&loops_cache_lock); + looptri = dm->looptris.array; + BLI_rw_mutex_unlock(&loops_cache_lock); } - return dm->looptris.array; + return looptri; } static CustomData *dm_getVertCData(DerivedMesh *dm) |