From 28fe7e440c62b9611129774b765b3d2aa8fbad5b Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Sat, 13 Sep 2014 12:05:16 -0400 Subject: [PATCH] fixbug 22611: don't close the program if we can't find button image If the main button image could not be loaded, the previous code would throw an exception of an obscure type "error". It appears that this was not caught anywhere except the main function in wesnoth.cpp and so the program would close immediately. I first tried to go into the gui initialization and construct buttons in try catch blocks, skipping ones that have problems, but rather than being able to proceed, this just causes a segfault because other parts of the code assume that all buttons have been constructed successfully. This means that not finding the image is necessarily a fatal error. My fix for the problem is, instead of throwing error, we throw the more standard "game::game_error". The new behavior is, if you try to load a theme with nonexistant images, then a black screen will appear with a dialog "error initializing button images! filename: buttons/dontexist.png" The game then returns to the title screen. Conflicts: src/widgets/button.cpp (just the #include reorder) --- src/widgets/button.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index 597be23a2b1b..b0c4115ac8b6 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -14,22 +14,23 @@ #define GETTEXT_DOMAIN "wesnoth-lib" +#include "widgets/button.hpp" + #include "global.hpp" -#include "widgets/button.hpp" -#include "game_config.hpp" +#include "filesystem.hpp" #include "font.hpp" -#include "text.hpp" -#include "marked-up_text.hpp" +#include "game_config.hpp" +#include "game_errors.hpp" #include "image.hpp" #include "log.hpp" +#include "marked-up_text.hpp" +#include "sdl/rect.hpp" #include "serialization/string_utils.hpp" #include "sound.hpp" #include "video.hpp" +#include "text.hpp" #include "wml_separators.hpp" -#include "sdl/rect.hpp" - -#include "filesystem.hpp" static lg::log_domain log_display("display"); #define ERR_DP LOG_STREAM(err, log_display) @@ -237,8 +238,11 @@ void button::load_images() { } if (button_image.null()) { - ERR_DP << "error initializing button!" << std::endl; - throw error(); + std::string err_msg = "error initializing button images! file name: "; + err_msg += button_image_name_; + err_msg += ".png"; + ERR_DP << err_msg << std::endl; + throw game::game_error(err_msg); } base_height_ = button_image->h;