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
parent 101ab2b301
commit 462a08a4ea
1 changed files with 16 additions and 5 deletions

@ -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<S,T>::do_search();
@ -444,8 +449,12 @@ protected:
virtual void clear_search()
{
search_generic<S,T>::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<df::unit *> *get_primary_list()