From 1cbc3a8f2b4772a96f173083e3a7b32b33b96f0b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 14 May 2020 14:58:54 +1000 Subject: Fix undo-push assert for some modes with zero undo steps Also fixes files not being tagged as modified with zero undo steps. --- source/blender/editors/undo/ed_undo.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/undo/ed_undo.c b/source/blender/editors/undo/ed_undo.c index f7300221028..6633e1c427c 100644 --- a/source/blender/editors/undo/ed_undo.c +++ b/source/blender/editors/undo/ed_undo.c @@ -79,15 +79,26 @@ static CLG_LogRef LOG = {"ed.undo"}; void ED_undo_push(bContext *C, const char *str) { CLOG_INFO(&LOG, 1, "name='%s'", str); + WM_file_tag_modified(); - const int steps = U.undosteps; - + wmWindowManager *wm = CTX_wm_manager(C); + int steps = U.undosteps; + + /* Ensure steps that have been initialized are always pushed, + * even when undo steps are zero. + * + * Note that some modes (paint, sculpt) initialize an undo step before an action runs, + * then accumulate changes there, or restore data from it in the case of 2D painting. + * + * For this reason we need to handle the undo step even when undo steps is set to zero. + */ + if ((steps <= 0) && wm->undo_stack->step_init != NULL) { + steps = 1; + } if (steps <= 0) { return; } - wmWindowManager *wm = CTX_wm_manager(C); - /* Only apply limit if this is the last undo step. */ if (wm->undo_stack->step_active && (wm->undo_stack->step_active->next == NULL)) { BKE_undosys_stack_limit_steps_and_memory(wm->undo_stack, steps - 1, 0); @@ -103,8 +114,6 @@ void ED_undo_push(bContext *C, const char *str) if (CLOG_CHECK(&LOG, 1)) { BKE_undosys_print(wm->undo_stack); } - - WM_file_tag_modified(); } /** -- cgit v1.2.3