From 875ecf7827aa107a18ce9bf14254d58d8676525e Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 14 Nov 2015 21:48:51 -0500 Subject: [PATCH] Update Core::top_viewscreen before calling state change handlers This was previously done right before SC_VIEWSCREEN_CHANGED events were handled, meaning that code handling earlier events that used top_viewscreen (rather than getCurViewscreen()) could refer to an invalid viewscreen, i.e. in the tick after it was deleted. Fixes #747 --- library/Core.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index 63357b145..a932e49e7 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -1721,6 +1721,14 @@ void Core::doUpdate(color_ostream &out, bool first_update) screen = screen->child; } + // detect if the viewscreen changed, and trigger events later + bool vs_changed = false; + if (screen != top_viewscreen) + { + top_viewscreen = screen; + vs_changed = true; + } + bool is_load_save = strict_virtual_cast(screen) || strict_virtual_cast(screen) || @@ -1770,12 +1778,8 @@ void Core::doUpdate(color_ostream &out, bool first_update) } } - // detect if the viewscreen changed - if (screen != top_viewscreen) - { - top_viewscreen = screen; + if (vs_changed) onStateChange(out, SC_VIEWSCREEN_CHANGED); - } if (df::global::pause_state) {