[Bf-blender-cvs] [61f9f50] master: Make object material drivers evaluation thread safe

Sergey Sharybin noreply at git.blender.org
Mon May 18 13:41:04 CEST 2015


Commit: 61f9f508a4473e1d2bb353396717b4e1a085e646
Author: Sergey Sharybin
Date:   Mon May 18 13:53:48 2015 +0500
Branches: master
https://developer.blender.org/rB61f9f508a4473e1d2bb353396717b4e1a085e646

Make object material drivers evaluation thread safe

Previously it was very easy to run into situation when two objects are sharing
the same materials with drivers which will cause threading access issues.

This actually only needed for the old depsgraph, but since it's still the one
we're using by default we'd better solve this issue.

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

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

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

diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index 46d68e7..d9373b9 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -37,6 +37,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
 #include "BLI_math.h"
+#include "BLI_threads.h"
 
 #include "BKE_global.h"
 #include "BKE_armature.h"
@@ -65,6 +66,8 @@
 #  define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH) printf
 #endif
 
+static ThreadMutex material_lock = BLI_MUTEX_INITIALIZER;
+
 void BKE_object_eval_local_transform(EvaluationContext *UNUSED(eval_ctx),
                                      Scene *UNUSED(scene),
                                      Object *ob)
@@ -239,12 +242,16 @@ void BKE_object_handle_data_update(EvaluationContext *eval_ctx,
 	 */
 	if (ob->totcol) {
 		int a;
-		for (a = 1; a <= ob->totcol; a++) {
-			Material *ma = give_current_material(ob, a);
-			if (ma) {
-				/* recursively update drivers for this material */
-				material_drivers_update(scene, ma, ctime);
+		if (ob->totcol != 0) {
+			BLI_mutex_lock(&material_lock);
+			for (a = 1; a <= ob->totcol; a++) {
+				Material *ma = give_current_material(ob, a);
+				if (ma) {
+					/* recursively update drivers for this material */
+					material_drivers_update(scene, ma, ctime);
+				}
 			}
+			BLI_mutex_unlock(&material_lock);
 		}
 	}
 	else if (ob->type == OB_LAMP)




More information about the Bf-blender-cvs mailing list