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
develop
lethosor 2015-11-14 21:48:51 -05:00
parent 9273c177c1
commit 875ecf7827
1 changed files with 9 additions and 5 deletions

@ -1721,6 +1721,14 @@ void Core::doUpdate(color_ostream &out, bool first_update)
screen = screen->child; 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 = bool is_load_save =
strict_virtual_cast<df::viewscreen_game_cleanerst>(screen) || strict_virtual_cast<df::viewscreen_game_cleanerst>(screen) ||
strict_virtual_cast<df::viewscreen_loadgamest>(screen) || strict_virtual_cast<df::viewscreen_loadgamest>(screen) ||
@ -1770,12 +1778,8 @@ void Core::doUpdate(color_ostream &out, bool first_update)
} }
} }
// detect if the viewscreen changed if (vs_changed)
if (screen != top_viewscreen)
{
top_viewscreen = screen;
onStateChange(out, SC_VIEWSCREEN_CHANGED); onStateChange(out, SC_VIEWSCREEN_CHANGED);
}
if (df::global::pause_state) if (df::global::pause_state)
{ {