From 1130c53cdb24b68d1871a03bad59fad9e6418f29 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 24 Feb 2014 19:12:40 +0600 Subject: Fix T38755: Crash when having cyclic dependency and curve deform Issue was caused by undefined object update order and in some cases NULL pointer will be de-referenced. Added on-demand curve path calculation, just the same creepy call of BKE_displist_make_curveTypes(). This violates DAG and might end up in a difficult to troubleshoot race condition if there'll be some issues with how dependencies are calculated in DAG, but this is the easiest and safest way to solve the bug at this stage, --- source/blender/modifiers/intern/MOD_array.c | 18 +++++++++++++++--- source/blender/modifiers/intern/MOD_curve.c | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'source/blender/modifiers') diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c index d2c44cd1281..1f233cc5492 100644 --- a/source/blender/modifiers/intern/MOD_array.c +++ b/source/blender/modifiers/intern/MOD_array.c @@ -65,6 +65,12 @@ #include #include +/* Due to cyclic dependencies it's possible that curve used for + * deformation here is not evaluated at the time of evaluating + * this modifier. + */ +#define CYCLIC_DEPENDENCY_WORKAROUND + static void initData(ModifierData *md) { ArrayModifierData *amd = (ArrayModifierData *) md; @@ -322,7 +328,7 @@ static void merge_first_last(BMesh *bm, } static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, - Object *ob, DerivedMesh *dm, + Scene *scene, Object *ob, DerivedMesh *dm, ModifierApplyFlag flag) { DerivedMesh *result; @@ -377,7 +383,13 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd, if (amd->fit_type == MOD_ARR_FITCURVE && amd->curve_ob) { Curve *cu = amd->curve_ob->data; if (cu) { - if (amd->curve_ob->curve_cache->path) { +#ifdef CYCLIC_DEPENDENCY_WORKAROUND + if (amd->curve_ob->curve_cache == NULL) { + BKE_displist_make_curveTypes(scene, amd->curve_ob, FALSE); + } +#endif + + if (amd->curve_ob->curve_cache && amd->curve_ob->curve_cache->path) { float scale = mat4_to_scale(amd->curve_ob->obmat); length = scale * amd->curve_ob->curve_cache->path->totdist; } @@ -575,7 +587,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *result; ArrayModifierData *amd = (ArrayModifierData *) md; - result = arrayModifier_doArray(amd, ob, dm, flag); + result = arrayModifier_doArray(amd, md->scene, ob, dm, flag); return result; } diff --git a/source/blender/modifiers/intern/MOD_curve.c b/source/blender/modifiers/intern/MOD_curve.c index 760fa8ffbe8..792fc7e7cf8 100644 --- a/source/blender/modifiers/intern/MOD_curve.c +++ b/source/blender/modifiers/intern/MOD_curve.c @@ -120,7 +120,7 @@ static void deformVerts(ModifierData *md, Object *ob, /* silly that defaxis and curve_deform_verts are off by 1 * but leave for now to save having to call do_versions */ - curve_deform_verts(cmd->object, ob, derivedData, vertexCos, numVerts, + curve_deform_verts(md->scene, cmd->object, ob, derivedData, vertexCos, numVerts, cmd->name, cmd->defaxis - 1); } -- cgit v1.2.3