gui2/tunit_create: Prevent null pointer dereferences

One code path in particular assumed that resources::controller is never
a null pointer, thus breaking unit tests.
This commit is contained in:
Ignacio R. Morelle 2015-10-19 23:10:20 -03:00
parent 9fd59b503f
commit 49e3d20e7b

View File

@ -288,9 +288,13 @@ void tunit_create::list_item_clicked(twindow& window)
std::stringstream str;
print_stats(str, selected_row);
const std::string& tc = "~RC("
+ u->flag_rgb() + ">"
+ team::get_side_color_index(resources::controller->play_controller::current_side()) + ")";
std::string tc;
if(resources::controller) {
tc = "~RC(" + u->flag_rgb() + ">" +
team::get_side_color_index(resources::controller->play_controller::current_side())
+ ")";
}
const std::string& alignment_name = unit_type::alignment_description(
u->alignment(),
@ -326,6 +330,10 @@ void tunit_create::list_item_clicked(twindow& window)
void tunit_create::profile_button_callback(twindow& window)
{
if(!disp_) {
return;
}
const int selected_row
= find_widget<tlistbox>(&window, "unit_type_list", false).get_selected_row();