Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Tönne <lukas.toenne@gmail.com>2014-01-30 16:06:48 +0400
committerLukas Tönne <lukas.toenne@gmail.com>2014-01-30 16:09:32 +0400
commit2b55d7895ced2c737e827e6a808634f730d275fc (patch)
tree093b89da72bde8905281b5259168ccea7bf29b14 /source/blender/modifiers
parent810c6d1880b9cb2944ab2bcb5eb60d8dedd97a64 (diff)
Fix T38403: Laplacian smooth on instanced objects leads to crash.
The laplacian modifiers (smooth and deform) use the OpenNL library, which is not threadsafe due to the use of a global context variable. Ideally this would be changed so that an explicit context can be created for every caller of the OpenNL functions, but since OpenNL's most recent version is from 2010 this is unlikely to happen. As a workaround for now just use a mutex to prevent conflicting OpenNL calls. Eventually OpenNL can be replaced by eigen or ceres.
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r--source/blender/modifiers/intern/MOD_laplaciandeform.c15
-rw-r--r--source/blender/modifiers/intern/MOD_laplaciansmooth.c10
-rw-r--r--source/blender/modifiers/intern/MOD_util.c22
-rw-r--r--source/blender/modifiers/intern/MOD_util.h17
4 files changed, 59 insertions, 5 deletions
diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.c
index defd287034e..7b5b73e0f6d 100644
--- a/source/blender/modifiers/intern/MOD_laplaciandeform.c
+++ b/source/blender/modifiers/intern/MOD_laplaciandeform.c
@@ -452,6 +452,10 @@ static void laplacianDeformPreview(LaplacianSystem *sys, float (*vertexCos)[3])
n = sys->total_verts;
na = sys->total_anchors;
+#ifdef OPENNL_THREADING_HACK
+ modifier_opennl_lock();
+#endif
+
if (!sys->is_matrix_computed) {
nlNewContext();
sys->context = nlGetCurrent();
@@ -530,12 +534,9 @@ static void laplacianDeformPreview(LaplacianSystem *sys, float (*vertexCos)[3])
sys->has_solution = false;
}
sys->is_matrix_computed = true;
- }
- else {
- if (!sys->has_solution) {
- return;
- }
+ }
+ else if (sys->has_solution) {
nlBegin(NL_SYSTEM);
nlBegin(NL_MATRIX);
@@ -589,6 +590,10 @@ static void laplacianDeformPreview(LaplacianSystem *sys, float (*vertexCos)[3])
sys->has_solution = false;
}
}
+
+#ifdef OPENNL_THREADING_HACK
+ modifier_opennl_unlock();
+#endif
}
static bool isValidVertexGroup(LaplacianDeformModifierData *lmd, Object *ob, DerivedMesh *dm)
diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.c b/source/blender/modifiers/intern/MOD_laplaciansmooth.c
index febd81e2f1b..130013af75b 100644
--- a/source/blender/modifiers/intern/MOD_laplaciansmooth.c
+++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.c
@@ -534,6 +534,11 @@ static void laplaciansmoothModifier_do(
sys->vert_centroid[1] = 0.0f;
sys->vert_centroid[2] = 0.0f;
memset_laplacian_system(sys, 0);
+
+#ifdef OPENNL_THREADING_HACK
+ modifier_opennl_lock();
+#endif
+
nlNewContext();
sys->context = nlGetCurrent();
nlSolverParameteri(NL_NB_VARIABLES, numVerts);
@@ -618,6 +623,11 @@ static void laplaciansmoothModifier_do(
}
nlDeleteContext(sys->context);
sys->context = NULL;
+
+#ifdef OPENNL_THREADING_HACK
+ modifier_opennl_unlock();
+#endif
+
delete_laplacian_system(sys);
}
diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c
index feae95bf777..0cc9b8bb77b 100644
--- a/source/blender/modifiers/intern/MOD_util.c
+++ b/source/blender/modifiers/intern/MOD_util.c
@@ -61,6 +61,10 @@
#include "RE_shader_ext.h"
+#ifdef OPENNL_THREADING_HACK
+#include "BLI_threads.h"
+#endif
+
void modifier_init_texture(Scene *scene, Tex *tex)
{
if (!tex)
@@ -235,6 +239,24 @@ void modifier_get_vgroup(Object *ob, DerivedMesh *dm, const char *name, MDeformV
}
}
+
+#ifdef OPENNL_THREADING_HACK
+
+static ThreadMutex opennl_context_mutex = BLI_MUTEX_INITIALIZER;
+
+void modifier_opennl_lock(void)
+{
+ BLI_mutex_lock(&opennl_context_mutex);
+}
+
+void modifier_opennl_unlock(void)
+{
+ BLI_mutex_unlock(&opennl_context_mutex);
+}
+
+#endif
+
+
/* only called by BKE_modifier.h/modifier.c */
void modifier_type_init(ModifierTypeInfo *types[])
{
diff --git a/source/blender/modifiers/intern/MOD_util.h b/source/blender/modifiers/intern/MOD_util.h
index 72077b5c000..cb851a51c64 100644
--- a/source/blender/modifiers/intern/MOD_util.h
+++ b/source/blender/modifiers/intern/MOD_util.h
@@ -52,4 +52,21 @@ struct DerivedMesh *get_dm_for_modifier(struct Object *ob, ModifierApplyFlag fla
void modifier_get_vgroup(struct Object *ob, struct DerivedMesh *dm,
const char *name, struct MDeformVert **dvert, int *defgrp_index);
+/* XXX workaround for non-threadsafe context in OpenNL (T38403)
+ * OpenNL uses global pointer for "current context", which causes
+ * conflict when multiple modifiers get evaluated in threaded depgraph.
+ * This is just a stupid hack to prevent assert failure / crash,
+ * otherwise we'd have to modify OpenNL on a large scale.
+ * OpenNL should be replaced eventually, there are other options (eigen, ceres).
+ * - lukas_t
+ */
+#ifdef WITH_OPENNL
+#define OPENNL_THREADING_HACK
+#endif
+
+#ifdef OPENNL_THREADING_HACK
+void modifier_opennl_lock(void);
+void modifier_opennl_unlock(void);
+#endif
+
#endif /* __MOD_UTIL_H__ */