Skip to content

Commit

Permalink
GUI2/Minimap: fixed a few issues with the new drawing impl
Browse files Browse the repository at this point in the history
First, the gamemap ptr wasn't reset if map creation failed, meaning the last data set was drawn instead.
Secondly, if no valid map data was provided before the canvas_draw_background function was called, you'd
get a nullptr dereference.

This fix also means invalid maps aren't drawn in the Load Game dialog as before, since the canvas will
clear the texture before calling canvas_draw_background, which will now do nothing if map_ is null.
  • Loading branch information
Vultraz committed Jul 26, 2017
1 parent 15bd8b7 commit 728fb47
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/gui/widgets/minimap.cpp
Expand Up @@ -92,6 +92,7 @@ void minimap::set_map_data(const std::string& map_data)
try {
map_.reset(new gamemap(std::make_shared<terrain_type_data>(*terrain_), map_data_));
} catch(incorrect_map_format_error& e) {
map_.reset(nullptr);
ERR_CF << "Error while loading the map: " << e.message << '\n';
}

Expand All @@ -101,7 +102,9 @@ void minimap::set_map_data(const std::string& map_data)

void minimap::canvas_draw_background(texture& tex)
{
image::render_minimap(tex, *map_);
if(map_) {
image::render_minimap(tex, *map_);
}
}

const std::string& minimap::get_control_type() const
Expand Down

0 comments on commit 728fb47

Please sign in to comment.