From 728fb47b83d513e44ffc54f09226341306d18d0c Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Tue, 25 Jul 2017 10:29:58 +1100 Subject: [PATCH] GUI2/Minimap: fixed a few issues with the new drawing impl 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. --- src/gui/widgets/minimap.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/minimap.cpp b/src/gui/widgets/minimap.cpp index 03e347efdf677..7cfc7f79a11e1 100644 --- a/src/gui/widgets/minimap.cpp +++ b/src/gui/widgets/minimap.cpp @@ -92,6 +92,7 @@ void minimap::set_map_data(const std::string& map_data) try { map_.reset(new gamemap(std::make_shared(*terrain_), map_data_)); } catch(incorrect_map_format_error& e) { + map_.reset(nullptr); ERR_CF << "Error while loading the map: " << e.message << '\n'; } @@ -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