From 79b703bb635ea719bbe31c1ece9884d2d298eaef Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 7 Nov 2019 16:52:03 +1100 Subject: Fix T69822: Switching sculpt objects breaks undo This introduces object mode tagging for data which hasn't yet been written back to the ID data. Now when selecting other sculpt objects, the original objects data is flushed back to the ID before writing a memfile undo step. --- source/blender/editors/curve/editcurve_undo.c | 12 +++++++++--- source/blender/editors/curve/editfont_undo.c | 17 +++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'source/blender/editors/curve') diff --git a/source/blender/editors/curve/editcurve_undo.c b/source/blender/editors/curve/editcurve_undo.c index f21b4f06246..ff3a1386fd9 100644 --- a/source/blender/editors/curve/editcurve_undo.c +++ b/source/blender/editors/curve/editcurve_undo.c @@ -208,9 +208,7 @@ static bool curve_undosys_poll(bContext *C) return (obedit != NULL); } -static bool curve_undosys_step_encode(struct bContext *C, - struct Main *UNUSED(bmain), - UndoStep *us_p) +static bool curve_undosys_step_encode(struct bContext *C, struct Main *bmain, UndoStep *us_p) { CurveUndoStep *us = (CurveUndoStep *)us_p; @@ -226,13 +224,18 @@ static bool curve_undosys_step_encode(struct bContext *C, for (uint i = 0; i < objects_len; i++) { Object *ob = objects[i]; + Curve *cu = ob->data; CurveUndoStep_Elem *elem = &us->elems[i]; elem->obedit_ref.ptr = ob; undocurve_from_editcurve(&elem->data, ob->data, ob->shapenr); + cu->editnurb->needs_flush_to_id = 1; us->step.data_size += elem->data.undo_size; } MEM_freeN(objects); + + bmain->is_memfile_undo_flush_needed = true; + return true; } @@ -260,6 +263,7 @@ static void curve_undosys_step_decode( continue; } undocurve_to_editcurve(bmain, &elem->data, obedit->data, &obedit->shapenr); + cu->editnurb->needs_flush_to_id = 1; DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY); } @@ -267,6 +271,8 @@ static void curve_undosys_step_decode( ED_undo_object_set_active_or_warn( CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG); + bmain->is_memfile_undo_flush_needed = true; + WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL); } diff --git a/source/blender/editors/curve/editfont_undo.c b/source/blender/editors/curve/editfont_undo.c index ae858ec4c24..26c0e5cf6c9 100644 --- a/source/blender/editors/curve/editfont_undo.c +++ b/source/blender/editors/curve/editfont_undo.c @@ -32,6 +32,7 @@ #include "BKE_context.h" #include "BKE_font.h" +#include "BKE_main.h" #include "BKE_undo_system.h" #include "DEG_depsgraph.h" @@ -341,23 +342,21 @@ static bool font_undosys_poll(bContext *C) return editfont_object_from_context(C) != NULL; } -static bool font_undosys_step_encode(struct bContext *C, - struct Main *UNUSED(bmain), - UndoStep *us_p) +static bool font_undosys_step_encode(struct bContext *C, struct Main *bmain, UndoStep *us_p) { FontUndoStep *us = (FontUndoStep *)us_p; us->obedit_ref.ptr = editfont_object_from_context(C); Curve *cu = us->obedit_ref.ptr->data; undofont_from_editfont(&us->data, cu); us->step.data_size = us->data.undo_size; + cu->editfont->needs_flush_to_id = 1; + bmain->is_memfile_undo_flush_needed = true; + return true; } -static void font_undosys_step_decode(struct bContext *C, - struct Main *UNUSED(bmain), - UndoStep *us_p, - int UNUSED(dir), - bool UNUSED(is_final)) +static void font_undosys_step_decode( + struct bContext *C, struct Main *bmain, UndoStep *us_p, int UNUSED(dir), bool UNUSED(is_final)) { /* TODO(campbell): undo_system: use low-level API to set mode. */ ED_object_mode_set(C, OB_MODE_EDIT); @@ -368,6 +367,8 @@ static void font_undosys_step_decode(struct bContext *C, Curve *cu = obedit->data; undofont_to_editfont(&us->data, cu); DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY); + cu->editfont->needs_flush_to_id = 1; + bmain->is_memfile_undo_flush_needed = true; WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL); } -- cgit v1.2.3