[Bf-blender-cvs] [754630cee4f] blender-v2.79a-release: Fix T52823: New Depsgraph - Shrinkwrap crashes blender

Sergey Sharybin noreply at git.blender.org
Mon Jan 8 16:55:27 CET 2018


Commit: 754630cee4fec23fc407876b5199c40ea892e8c3
Author: Sergey Sharybin
Date:   Tue Sep 19 16:09:35 2017 +0500
Branches: blender-v2.79a-release
https://developer.blender.org/rB754630cee4fec23fc407876b5199c40ea892e8c3

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 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)



More information about the Bf-blender-cvs mailing list