From 462a08a4eaa5ab9f418d9bc3670d2ed199073009 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Tue, 2 Apr 2013 12:03:37 +0400 Subject: [PATCH] Fix the search plugin crashing the military screen. The cause of the crash is that the right list is used for multiple different things in different pages, so when cleaning up after a page switch it is not acceptable to mess with it in any way. However the search plugin changed its length, thus causing a crash if the new contents were shorter than the original candidate list. --- plugins/search.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/plugins/search.cpp b/plugins/search.cpp index 4e502b838..541fc9506 100644 --- a/plugins/search.cpp +++ b/plugins/search.cpp @@ -422,12 +422,17 @@ protected: virtual bool can_init(S *screen) { auto list = getLayerList(screen); - if (!list->active) + if (!is_list_valid(screen) || !list->active) return false; return true; } + virtual bool is_list_valid(S*) + { + return true; + } + virtual void do_search() { search_generic::do_search(); @@ -444,8 +449,12 @@ protected: virtual void clear_search() { search_generic::clear_search(); - auto list = getLayerList(this->viewscreen); - list->num_entries = this->get_primary_list()->size(); + + if (is_list_valid(this->viewscreen)) + { + auto list = getLayerList(this->viewscreen); + list->num_entries = this->get_primary_list()->size(); + } } private: @@ -1208,12 +1217,14 @@ public: return 'q'; } - bool can_init(df::viewscreen_layer_militaryst *screen) + // When not on the positions page, this list is used for something + // else entirely, so screwing with it seriously breaks stuff. + bool is_list_valid(df::viewscreen_layer_militaryst *screen) { if (screen->page != df::viewscreen_layer_militaryst::Positions) return false; - return military_search_base::can_init(screen); + return true; } vector *get_primary_list()