From 69d22a42d06f6f90beacffd53dd5627337ce8375 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Dec 2023 11:09:28 +1100 Subject: [PATCH] Fix #116297: Context override error passing in a window without a screen When overriding the contexts window but not the screen, the context override would attempt to use the current screen with the new window. This raised an error and could crash when editing properties in the key-map editor for the "context toggle" operator. --- source/blender/python/intern/bpy_rna_context.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/blender/python/intern/bpy_rna_context.cc b/source/blender/python/intern/bpy_rna_context.cc index 21a0dd825df..9d6ba06a28f 100644 --- a/source/blender/python/intern/bpy_rna_context.cc +++ b/source/blender/python/intern/bpy_rna_context.cc @@ -164,6 +164,13 @@ static PyObject *bpy_rna_context_temp_override_enter(BPyContextTempOverride *sel self->ctx_init.area_is_set = (self->ctx_init.area != area); self->ctx_init.region_is_set = (self->ctx_init.region != region); + /* When the screen isn't passed but a window is, match the screen to the window, + * it's important to do this after setting `self->ctx_init.screen_is_set` because the screen is + * *not* set, only the window, restoring the window will also restore its screen, see #116297. */ + if ((self->ctx_temp.win_is_set == true) && (self->ctx_temp.screen_is_set == false)) { + screen = win ? WM_window_get_active_screen(win) : nullptr; + } + /* NOTE(@ideasman42): Regarding sanity checks. * There are 3 different situations to be accounted for here regarding overriding windowing data. *