diff --git a/changelog b/changelog index 7cb3dcfa26e..95abef035ba 100644 --- a/changelog +++ b/changelog @@ -55,6 +55,7 @@ Version 1.13.5+dev: high HP, drain, slow, berserk, etc.) it's significantly faster than the default damage calculation method. * Miscellaneous and bug fixes: + * Fixed a stray ; character appearing pre-entered in the command console. * Fixed bug in wesnothd that was causing server crashes if game with multiple network and local players was ran. * Added a tab to run the wmlxgettext tool to GUI.pyw diff --git a/players_changelog b/players_changelog index 00f9eb0f8e6..1626ce1ad7b 100644 --- a/players_changelog +++ b/players_changelog @@ -18,6 +18,8 @@ Version 1.13.5+dev: probabilities. This method is inexact, but in very complex battles (extremely high HP, drain, slow, berserk, etc.) it's significantly faster than the default damage calculation method. + * Miscellaneous and bug fixes: + * Fixed a stray ; character appearing pre-entered in the command console. Version 1.13.5: * Campaigns: diff --git a/src/events.cpp b/src/events.cpp index 46a3a161cb5..d3ea672d051 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #define ERR_GEN LOG_STREAM(err, lg::general) @@ -43,7 +44,10 @@ namespace events void context::add_handler(sdl_handler* ptr) { - handlers.push_back(ptr); + /* Add new handlers to the staging list initially. + This ensures that if an event handler adds more handlers, the new handlers + won't be called for the event that caused them to be added. */ + staging_handlers.push_back(ptr); } bool context::remove_handler(sdl_handler* ptr) @@ -68,7 +72,18 @@ bool context::remove_handler(sdl_handler* ptr) if(i == handlers.end()) { --depth; - return false; + + // The handler may be in the staging area. Search it from there. + auto j = std::find(staging_handlers.begin(), staging_handlers.end(), ptr); + if (j != staging_handlers.end()) + { + staging_handlers.erase(j); + return true; + } + else + { + return false; + } } if(i == focused_handler) { @@ -131,6 +146,12 @@ void context::set_focus(const sdl_handler* ptr) } } +void context::add_staging_handlers() +{ + std::copy(staging_handlers.begin(), staging_handlers.end(), std::back_inserter(handlers)); + staging_handlers.clear(); +} + context::~context() { for (sdl_handler* h : handlers) @@ -445,6 +466,11 @@ void pump() ev_end = events.end(); for(ev_it = events.begin(); ev_it != ev_end; ++ev_it){ + for (context& c : event_contexts) + { + c.add_staging_handlers(); + } + SDL_Event &event = *ev_it; switch(event.type) { diff --git a/src/events.hpp b/src/events.hpp index 3a1aba977dc..c39d6ccd53f 100644 --- a/src/events.hpp +++ b/src/events.hpp @@ -41,7 +41,8 @@ class context public: context() : handlers(), - focused_handler(handlers.end()) + focused_handler(handlers.end()), + staging_handlers() { } @@ -53,9 +54,11 @@ public: bool remove_handler(sdl_handler* ptr); void cycle_focus(); void set_focus(const sdl_handler* ptr); + void add_staging_handlers(); handler_list handlers; handler_list::iterator focused_handler; + std::vector staging_handlers; }; //any classes that derive from this class will automatically