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.
develop
Alexander Gavrilov 2013-04-02 12:03:37 +04:00 committed by Anuradha Dissanayake
parent d7c91975c0
commit 9d6f202988
1 changed files with 16 additions and 5 deletions

@ -422,12 +422,17 @@ protected:
virtual bool can_init(S *screen) virtual bool can_init(S *screen)
{ {
auto list = getLayerList(screen); auto list = getLayerList(screen);
if (!list->active) if (!is_list_valid(screen) || !list->active)
return false; return false;
return true; return true;
} }
virtual bool is_list_valid(S*)
{
return true;
}
virtual void do_search() virtual void do_search()
{ {
search_generic<S,T>::do_search(); search_generic<S,T>::do_search();
@ -444,9 +449,13 @@ protected:
virtual void clear_search() virtual void clear_search()
{ {
search_generic<S,T>::clear_search(); search_generic<S,T>::clear_search();
if (is_list_valid(this->viewscreen))
{
auto list = getLayerList(this->viewscreen); auto list = getLayerList(this->viewscreen);
list->num_entries = this->get_primary_list()->size(); list->num_entries = this->get_primary_list()->size();
} }
}
private: private:
static df::layer_object_listst *getLayerList(const df::viewscreen_layer *layer) static df::layer_object_listst *getLayerList(const df::viewscreen_layer *layer)
@ -1208,12 +1217,14 @@ public:
return 'q'; 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) if (screen->page != df::viewscreen_layer_militaryst::Positions)
return false; return false;
return military_search_base::can_init(screen); return true;
} }
vector<df::unit *> *get_primary_list() vector<df::unit *> *get_primary_list()