diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-09-19 14:09:35 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-09-19 14:12:05 +0300 |
commit | 1a4442b3dbadd685b9c6a70fa9694748b2a6e2d3 (patch) | |
tree | 736d8ca52f76374a0e77389f5972aa1c8d35fc61 /source | |
parent | 495d3c8dd75421be2f3f5c5b31690eaedacf6e4e (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')
-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 e53f14291b7..12d0c68f4d8 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) |