Fix T92464: Operators fail after opening blend files via an operator

Operators such as setting the object mode failed after calling
WM_OT_open_mainfile from Python.

Keep the window after loading a file outside the main event loop.
This commit is contained in:
Campbell Barton 2021-11-02 21:57:23 +11:00
parent 0c3b215e7d
commit 9bd97e62ad
Notes: blender-bot 2023-02-14 05:12:59 +01:00
Referenced by commit 50b0503a11, Revert "Fix T92464: Operators fail after opening blend files via an operator"
Referenced by issue #92818, passing load_ui=True to read_homefile() or open_mainfile() crashes Blender
Referenced by issue #92464, RuntimeError on bpy.ops.object.mode_set if executed from terminal but works in blender's text editor
1 changed files with 12 additions and 0 deletions

View File

@ -769,6 +769,18 @@ static void wm_file_read_post(bContext *C, const struct wmFileReadPost_Params *p
WM_toolsystem_init(C);
}
}
/* Keep last. */
if (use_data) {
if (!G.background) {
/* Special case, when calling indirectly (from a Python script for example),
* the event loop wont run again to set the active window.
* Set the window here to allow scripts to continue running other operations, see: T92464. */
if (wm->op_undo_depth > 0) {
CTX_wm_window_set(C, wm->windows.first);
}
}
}
}
/** \} */