diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2021-03-29 11:14:53 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2021-03-29 12:00:32 +0300 |
commit | 3681a619ded1a6b225befc31ef87259081fb61e5 (patch) | |
tree | 35f841fc7287689e25c95da5aa89842b75a9fd7b /source/blender/blenkernel/intern/lattice.c | |
parent | 8034b276ba6c5369a356a1b8f5e858305f8b47b9 (diff) |
Fix T78650: Lattice evaluation writes to shared data
Fix the data management bug where evaluation of lattice objects would
write back to the CoW copy of the Lattice ID, even when that copy was
shared between objects.
Each lattice object evaluation now stores its own evaluated data copy
via `BKE_object_eval_assign_data()`.
Reviewed By: sergey
Maniphest Tasks: T78650
Differential Revision: https://developer.blender.org/D10790
Diffstat (limited to 'source/blender/blenkernel/intern/lattice.c')
-rw-r--r-- | source/blender/blenkernel/intern/lattice.c | 61 |
1 files changed, 20 insertions, 41 deletions
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 7c451051727..48104e72825 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -540,10 +540,12 @@ void BKE_lattice_vert_coords_apply(Lattice *lt, const float (*vert_coords)[3]) void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Object *ob) { + BKE_object_free_derived_caches(ob); + if (ob->runtime.curve_cache == NULL) { + ob->runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for lattice"); + } + Lattice *lt = ob->data; - /* Get vertex coordinates from the original copy; - * otherwise we get already-modified coordinates. */ - Object *ob_orig = DEG_get_original_object(ob); VirtualModifierData virtualModifierData; ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData); float(*vert_coords)[3] = NULL; @@ -551,13 +553,6 @@ void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Objec const bool is_editmode = (lt->editlatt != NULL); const ModifierEvalContext mectx = {depsgraph, ob, 0}; - if (ob->runtime.curve_cache) { - BKE_displist_free(&ob->runtime.curve_cache->disp); - } - else { - ob->runtime.curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for lattice"); - } - for (; md; md = md->next) { const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type); @@ -577,49 +572,33 @@ void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Objec continue; } - if (!vert_coords) { - Lattice *lt_orig = ob_orig->data; - if (lt_orig->editlatt) { - lt_orig = lt_orig->editlatt->latt; - } - vert_coords = BKE_lattice_vert_coords_alloc(lt_orig, &numVerts); + if (vert_coords == NULL) { + /* Get either the edit-mode or regular lattice, whichever is in use now. */ + const Lattice *effective_lattice = BKE_object_get_lattice(ob); + vert_coords = BKE_lattice_vert_coords_alloc(effective_lattice, &numVerts); } + mti->deformVerts(md, &mectx, NULL, vert_coords, numVerts); } - if (ob->id.tag & LIB_TAG_COPIED_ON_WRITE) { - if (vert_coords) { - BKE_lattice_vert_coords_apply(ob->data, vert_coords); - MEM_freeN(vert_coords); - } + if (vert_coords == NULL) { + return; } - else { - /* Displist won't do anything; this is just for posterity's sake until we remove it. */ - if (!vert_coords) { - Lattice *lt_orig = ob_orig->data; - if (lt_orig->editlatt) { - lt_orig = lt_orig->editlatt->latt; - } - vert_coords = BKE_lattice_vert_coords_alloc(lt_orig, &numVerts); - } - - DispList *dl = MEM_callocN(sizeof(*dl), "lt_dl"); - dl->type = DL_VERTS; - dl->parts = 1; - dl->nr = numVerts; - dl->verts = (float *)vert_coords; - BLI_addtail(&ob->runtime.curve_cache->disp, dl); + Lattice *lt_eval = BKE_object_get_evaluated_lattice(ob); + if (lt_eval == NULL) { + BKE_id_copy_ex(NULL, <->id, (ID **)<_eval, LIB_ID_COPY_LOCALIZE); + BKE_object_eval_assign_data(ob, <_eval->id, true); } + + BKE_lattice_vert_coords_apply(lt_eval, vert_coords); + MEM_freeN(vert_coords); } struct MDeformVert *BKE_lattice_deform_verts_get(const struct Object *oblatt) { - Lattice *lt = (Lattice *)oblatt->data; BLI_assert(oblatt->type == OB_LATTICE); - if (lt->editlatt) { - lt = lt->editlatt->latt; - } + Lattice *lt = BKE_object_get_lattice(oblatt); return lt->dvert; } |