From 937731dff1af4910dc94646904106432c14b2042 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 7 Feb 2019 20:27:11 +1100 Subject: Fix T61272: Undo fails to track multi-edit mode enter/exit Objects leaving edit-mode weren't restored by edit-mode undo steps. --- source/blender/editors/curve/editcurve_undo.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'source/blender/editors/curve/editcurve_undo.c') diff --git a/source/blender/editors/curve/editcurve_undo.c b/source/blender/editors/curve/editcurve_undo.c index a586e94a6f9..e9586594274 100644 --- a/source/blender/editors/curve/editcurve_undo.c +++ b/source/blender/editors/curve/editcurve_undo.c @@ -213,9 +213,11 @@ static bool curve_undosys_step_encode(struct bContext *C, struct Main *UNUSED(bm { CurveUndoStep *us = (CurveUndoStep *)us_p; + /* Important not to use the 3D view when getting objects because all objects + * outside of this list will be moved out of edit-mode when reading back undo steps. */ ViewLayer *view_layer = CTX_data_view_layer(C); uint objects_len = 0; - Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, CTX_wm_view3d(C), &objects_len); + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, NULL, &objects_len); us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__); us->elems_len = objects_len; @@ -234,12 +236,14 @@ static bool curve_undosys_step_encode(struct bContext *C, struct Main *UNUSED(bm static void curve_undosys_step_decode(struct bContext *C, struct Main *UNUSED(bmain), UndoStep *us_p, int UNUSED(dir)) { - /* TODO(campbell): undo_system: use low-level API to set mode. */ - ED_object_mode_set(C, OB_MODE_EDIT); - BLI_assert(curve_undosys_poll(C)); - CurveUndoStep *us = (CurveUndoStep *)us_p; + /* Load all our objects into edit-mode, clear everything else. */ + ED_undo_object_editmode_restore_helper( + C, &us->elems[0].obedit_ref.ptr, us->elems_len, sizeof(*us->elems)); + + BLI_assert(curve_undosys_poll(C)); + for (uint i = 0; i < us->elems_len; i++) { CurveUndoStep_Elem *elem = &us->elems[i]; Object *obedit = elem->obedit_ref.ptr; -- cgit v1.2.3