diff options
author | Jacques Lucke <jacques@blender.org> | 2020-08-11 14:24:52 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-08-11 14:24:52 +0300 |
commit | 6d888133da1ce31f4cd68f44d1209534173b4562 (patch) | |
tree | e7504979e021155578c37520da91660bb8440d2b /source/blender/windowmanager/intern | |
parent | bb5cc3bccf4901a1759b171033147e717d9eb1c4 (diff) |
Timers: set first window as context in timer
This avoids some crashes when running Python code in timers.
Reviewers: brecht
Differential Revision: https://developer.blender.org/D8531
Diffstat (limited to 'source/blender/windowmanager/intern')
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 05ef4bfac30..8dbb608cd30 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -387,6 +387,18 @@ void wm_event_do_refresh_wm_and_depsgraph(bContext *C) CTX_wm_window_set(C, NULL); } +static void wm_event_execute_timers(bContext *C) +{ + wmWindowManager *wm = CTX_wm_manager(C); + + /* Set the first window as context, so that there is some minimal context. This avoids crashes + * when calling code that assumes that there is always a window in the context (which many + * operators do). */ + CTX_wm_window_set(C, wm->windows.first); + BLI_timer_execute(); + CTX_wm_window_set(C, NULL); +} + /* called in mainloop */ void wm_event_do_notifiers(bContext *C) { @@ -398,7 +410,7 @@ void wm_event_do_notifiers(bContext *C) return; } - BLI_timer_execute(); + wm_event_execute_timers(C); /* disable? - keep for now since its used for window level notifiers. */ #if 1 |