Author: ilor
Date: Mon Aug 11 17:32:45 2008
New Revision: 28463
URL: http://svn.gna.org/viewcvs/wesnoth?rev=28463&view=rev
Log:
editor2: exception handling and action leak detection
Modified:
trunk/src/editor2/action_base.hpp
trunk/src/editor2/editor_common.hpp
trunk/src/editor2/editor_controller.cpp
trunk/src/editor2/editor_main.cpp
trunk/src/editor2/editor_map.hpp
Modified: trunk/src/editor2/action_base.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action_base.hpp?rev=28463&r1=28462&r2=28463&view=diff
==============================================================================
--- trunk/src/editor2/action_base.hpp (original)
+++ trunk/src/editor2/action_base.hpp Mon Aug 11 17:32:45 2008
@@ -86,16 +86,28 @@
//TODO: add messages etc
struct editor_action_exception : public editor_exception
{
+ editor_action_exception(const char* msg)
+ : editor_exception(msg)
+ {
+ }
};
//thrown instead of a "todo" debug message
struct editor_action_not_implemented : public editor_action_exception
{
+ editor_action_not_implemented()
+ : editor_action_exception("Action not implemented")
+ {
+ }
};
//used when e.g. passed parameters are invalid
struct editor_action_creation_fail : public editor_action_exception
{
+ editor_action_creation_fail()
+ : editor_action_exception("Error creating action object")
+ {
+ }
};
} //end namespace editor2
Modified: trunk/src/editor2/editor_common.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_common.hpp?rev=28463&r1=28462&r2=28463&view=diff
==============================================================================
--- trunk/src/editor2/editor_common.hpp (original)
+++ trunk/src/editor2/editor_common.hpp Mon Aug 11 17:32:45 2008
@@ -37,6 +37,12 @@
struct editor_exception : public std::exception
{
+ editor_exception(const char* msg)
+ : msg(msg)
+ {
+ }
+ const char* what() const throw() { return msg; }
+ const char* msg;
};
Modified: trunk/src/editor2/editor_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=28463&r1=28462&r2=28463&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Mon Aug 11 17:32:45 2008
@@ -129,8 +129,13 @@
EXIT_STATUS editor_controller::main_loop()
{
- while (!do_quit_) {
- play_slice();
+ try {
+ while (!do_quit_) {
+ play_slice();
+ }
+ } catch (editor_exception& e) {
+ gui::message_dialog(gui(), _("Fatal errror"), e.what()).show();
+ return EXIT_ERROR;
}
return quit_mode_;
}
Modified: trunk/src/editor2/editor_main.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_main.cpp?rev=28463&r1=28462&r2=28463&view=diff
==============================================================================
--- trunk/src/editor2/editor_main.cpp (original)
+++ trunk/src/editor2/editor_main.cpp Mon Aug 11 17:32:45 2008
@@ -12,6 +12,7 @@
See the COPYING file for more details.
*/
+#include "action_base.hpp"
#include "editor_main.hpp"
#include "editor_common.hpp"
#include "editor_controller.hpp"
@@ -22,12 +23,21 @@
EXIT_STATUS start(config& game_conf, CVideo& video)
{
- hotkey::scope_changer h_(game_conf, "hotkey_editor");
- hotkey::deactivate_all_scopes();
- hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
- hotkey::set_scope_active(hotkey::SCOPE_EDITOR);
- editor_controller editor(game_conf, video);
- EXIT_STATUS e = editor.main_loop();
+ EXIT_STATUS e = EXIT_ERROR;
+ try {
+ hotkey::scope_changer h_(game_conf, "hotkey_editor");
+ hotkey::deactivate_all_scopes();
+ hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
+ hotkey::set_scope_active(hotkey::SCOPE_EDITOR);
+ editor_controller editor(game_conf, video);
+ e = editor.main_loop();
+ } catch (editor_exception& e) {
+ ERR_ED << "Editor exception in editor2::start: " << e.what() <<
"\n";
+ throw;
+ }
+ if (editor_action::get_instance_count() != 0) {
+ WRN_ED << "Possibly leaked " <<
editor_action::get_instance_count() << " action objects\n";
+ }
return e;
}
Modified: trunk/src/editor2/editor_map.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_map.hpp?rev=28463&r1=28462&r2=28463&view=diff
==============================================================================
--- trunk/src/editor2/editor_map.hpp (original)
+++ trunk/src/editor2/editor_map.hpp Mon Aug 11 17:32:45 2008
@@ -25,10 +25,18 @@
struct editor_map_operation_exception : public editor_exception
{
+ editor_map_operation_exception()
+ : editor_exception("Map operation error. Check debug log for details.")
+ {
+ }
};
struct editor_map_integrity_error : public editor_exception
{
+ editor_map_integrity_error()
+ : editor_exception("Map integrity error. Check debug log for details.")
+ {
+ }
};
/**
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits