[Bf-blender-cvs] [1b7c361fbb3] master: WM: disable undo operators in background mode & at startup

Campbell Barton noreply at git.blender.org
Fri Feb 1 04:08:36 CET 2019


Commit: 1b7c361fbb320744e6b7cc0c03b5f850e8fbfd9e
Author: Campbell Barton
Date:   Fri Feb 1 14:05:33 2019 +1100
Branches: master
https://developer.blender.org/rB1b7c361fbb320744e6b7cc0c03b5f850e8fbfd9e

WM: disable undo operators in background mode & at startup

Show an error instead of crashing, see: T60934

===================================================================

M	source/blender/editors/undo/ed_undo.c

===================================================================

diff --git a/source/blender/editors/undo/ed_undo.c b/source/blender/editors/undo/ed_undo.c
index 6f39be0f7c6..d427086af66 100644
--- a/source/blender/editors/undo/ed_undo.c
+++ b/source/blender/editors/undo/ed_undo.c
@@ -351,11 +351,31 @@ static int ed_undo_redo_exec(bContext *C, wmOperator *UNUSED(op))
 	return ret;
 }
 
+/* Disable in background mode, we could support if it's useful, T60934. */
+
+static bool ed_undo_is_init_poll(bContext *C)
+{
+	wmWindowManager *wm = CTX_wm_manager(C);
+	if (wm->undo_stack == NULL) {
+		CTX_wm_operator_poll_msg_set(C, "Undo disabled in background mode or at startup");
+		return false;
+	}
+	return true;
+}
+
+static bool ed_undo_is_init_and_screenactive_poll(bContext *C)
+{
+	if (ed_undo_is_init_poll(C) == false) {
+		return false;
+	}
+	return ED_operator_screenactive(C);
+}
+
 static bool ed_undo_redo_poll(bContext *C)
 {
 	wmOperator *last_op = WM_operator_last_redo(C);
-	return last_op && ED_operator_screenactive(C) &&
-		WM_operator_check_ui_enabled(C, last_op->type->name);
+	return (last_op && ed_undo_is_init_and_screenactive_poll(C) &&
+	        WM_operator_check_ui_enabled(C, last_op->type->name));
 }
 
 void ED_OT_undo(wmOperatorType *ot)
@@ -367,7 +387,7 @@ void ED_OT_undo(wmOperatorType *ot)
 
 	/* api callbacks */
 	ot->exec = ed_undo_exec;
-	ot->poll = ED_operator_screenactive;
+	ot->poll = ed_undo_is_init_and_screenactive_poll;
 }
 
 void ED_OT_undo_push(wmOperatorType *ot)
@@ -379,6 +399,7 @@ void ED_OT_undo_push(wmOperatorType *ot)
 
 	/* api callbacks */
 	ot->exec = ed_undo_push_exec;
+	ot->poll = ed_undo_is_init_poll;
 
 	ot->flag = OPTYPE_INTERNAL;
 
@@ -394,7 +415,7 @@ void ED_OT_redo(wmOperatorType *ot)
 
 	/* api callbacks */
 	ot->exec = ed_redo_exec;
-	ot->poll = ED_operator_screenactive;
+	ot->poll = ed_undo_is_init_and_screenactive_poll;
 }
 
 void ED_OT_undo_redo(wmOperatorType *ot)
@@ -605,7 +626,7 @@ void ED_OT_undo_history(wmOperatorType *ot)
 	/* api callbacks */
 	ot->invoke = undo_history_invoke;
 	ot->exec = undo_history_exec;
-	ot->poll = ED_operator_screenactive;
+	ot->poll = ed_undo_is_init_and_screenactive_poll;
 
 	RNA_def_int(ot->srna, "item", 0, 0, INT_MAX, "Item", "", 0, INT_MAX);



More information about the Bf-blender-cvs mailing list