Skip to content

Commit

Permalink
fixbug 22611: don't close the program if we can't find button image
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
cbeck88 committed Sep 13, 2014
1 parent 1c69131 commit 28fe7e4
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/widgets/button.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 28fe7e4

Please sign in to comment.