From a478d502dd2512a63657818e19ee2b74c1848bec Mon Sep 17 00:00:00 2001 From: Antonio Vazquez Date: Wed, 24 Mar 2021 16:01:44 +0100 Subject: GPencil: Fix unreported crash when apply Lattice modifier This error was produced because now it is possible to have several Lattice modifiers and the Bake was removing the lattice data of all modifiers. Now the data is only recalculated and removed for the current modifier. Also some cleanup of comments. --- .../gpencil_modifiers/intern/MOD_gpencillattice.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'source/blender/gpencil_modifiers') diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencillattice.c b/source/blender/gpencil_modifiers/intern/MOD_gpencillattice.c index 4efc1d9eaae..2934b89c747 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencillattice.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencillattice.c @@ -136,36 +136,39 @@ static void bakeModifier(Main *UNUSED(bmain), bGPdata *gpd = ob->data; int oldframe = (int)DEG_get_ctime(depsgraph); - if (mmd->object == NULL) { + if ((mmd->object == NULL) || (mmd->object->type != OB_LATTICE)) { return; } LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) { LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) { - /* apply lattice effects on this frame - * NOTE: this assumes that we don't want lattice animation on non-keyframed frames + /* Apply lattice effects on this frame + * NOTE: this assumes that we don't want lattice animation on non-keyframed frames. */ CFRA = gpf->framenum; BKE_scene_graph_update_for_newframe(depsgraph); - /* recalculate lattice data */ - BKE_gpencil_lattice_init(ob); + /* Recalculate lattice data. */ + if (mmd->cache_data) { + BKE_lattice_deform_data_destroy(mmd->cache_data); + } + mmd->cache_data = BKE_lattice_deform_data_create(mmd->object, ob); - /* compute lattice effects on this frame */ + /* Compute lattice effects on this frame. */ LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) { deformStroke(md, depsgraph, ob, gpl, gpf, gps); } } } - /* free lingering data */ + /* Free lingering data. */ ldata = (struct LatticeDeformData *)mmd->cache_data; if (ldata) { BKE_lattice_deform_data_destroy(ldata); mmd->cache_data = NULL; } - /* return frame state and DB to original state */ + /* Return frame state and DB to original state. */ CFRA = oldframe; BKE_scene_graph_update_for_newframe(depsgraph); } -- cgit v1.2.3