Fix crash after hitting enter when no units match the recruit list filter

This is essentially the same as
https://github.com/wesnoth/wesnoth/pull/3476, except that it is applied
to the recruit dialog rather than the recall dialog.
This commit is contained in:
Anna Henningsen 2019-03-05 15:13:33 +01:00 committed by josteph
parent 0379e2e832
commit 7f71d81478

View file

@ -277,7 +277,12 @@ void menu_handler::recruit(int side_num, const map_location& last_hex)
if(dlg.show()) {
map_location recruit_hex = last_hex;
do_recruit(sample_units[dlg.get_selected_index()]->id(), side_num, recruit_hex);
int index = dlg.get_selected_index();
if (index < 0) {
gui2::show_transient_message("", _("No unit recruited"));
return;
}
do_recruit(sample_units[index]->id(), side_num, recruit_hex);
}
}