[Bf-blender-cvs] [1a4442b3dba] master: Fix T52823: New Depsgraph - Shrinkwrap crashes blender

Sergey Sharybin noreply at git.blender.org
Tue Sep 19 13:12:24 CEST 2017


Commit: 1a4442b3dbadd685b9c6a70fa9694748b2a6e2d3
Author: Sergey Sharybin
Date:   Tue Sep 19 16:09:35 2017 +0500
Branches: master
https://developer.blender.org/rB1a4442b3dbadd685b9c6a70fa9694748b2a6e2d3

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!

===================================================================

M	source/blender/blenkernel/intern/DerivedMesh.c

===================================================================

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)



More information about the Bf-blender-cvs mailing list