Undo System: basic support in background mode

Some developers were using undo for their scripts, this allows for undo
pushes in background mode, however - as with 2.7x, undo isn't
initialized at startup in background mode.

See replies to T60934
This commit is contained in:
Campbell Barton 2019-02-08 10:15:11 +11:00
parent e1edb51699
commit 3d16a268ee
Notes: blender-bot 2023-02-14 19:21:02 +01:00
Referenced by issue #90972, Crash calling Mesh.clear_geometry in edit-mode
Referenced by issue #61342, segfault when clicking Use Nodes in 2D workspace
Referenced by issue #61343, Crash when selecting image source drop down in Image Texture node
Referenced by issue #61345, Creating a texture crashes Blender
Referenced by issue #61324, EXCEPTION_ACCESS_VIOLATION using bpy.utils.previews
Referenced by issue #61305, bug on material properties panel
Referenced by issue #61306, Blender 2.8 close with a default cube, and material is clicked
Referenced by issue #61307, Blender Crashes when Material Tab is clicked
Referenced by issue #61314, crash when drawing images, fonts etc using icon_value arg or template_icon_view function
Referenced by issue #61315, Blender 2.80 crashes at start up
Referenced by issue #61196, clipping border allows selection of clipped vertices when x-ray mode is disabled
Referenced by issue #55628, Crash when creating new material slots
Referenced by issue blender/blender-addons#60934, Undo crashes when calling bpy.ops.ed.undo_history(index=0) from Python in background mode
1 changed files with 12 additions and 2 deletions

View File

@ -323,6 +323,15 @@ static int ed_undo_exec(bContext *C, wmOperator *op)
static int ed_undo_push_exec(bContext *C, wmOperator *op)
{
if (G.background) {
/* Exception for background mode, see: T60934.
* Note: since the undo stack isn't initialized on startup, background mode behavior
* won't match regular usage, this is just for scripts to do explicit undo pushes. */
wmWindowManager *wm = CTX_wm_manager(C);
if (wm->undo_stack == NULL) {
wm->undo_stack = BKE_undosys_stack_create();
}
}
char str[BKE_UNDO_STR_MAX];
RNA_string_get(op->ptr, "message", str);
ED_undo_push(C, str);
@ -357,7 +366,7 @@ 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");
CTX_wm_operator_poll_msg_set(C, "Undo disabled at startup");
return false;
}
return true;
@ -399,7 +408,8 @@ void ED_OT_undo_push(wmOperatorType *ot)
/* api callbacks */
ot->exec = ed_undo_push_exec;
ot->poll = ed_undo_is_init_poll;
/* Unlike others undo operators this initializes undo stack. */
ot->poll = ED_operator_screenactive;
ot->flag = OPTYPE_INTERNAL;