From 61f9f508a4473e1d2bb353396717b4e1a085e646 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 18 May 2015 13:53:48 +0500 Subject: 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. --- source/blender/blenkernel/intern/object_update.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c index 46d68e7ccab..d9373b9595a 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) -- cgit v1.2.3