Skip to content

Commit

Permalink
Game Events/Manager: skip disabled assertion if write_events is calle…
Browse files Browse the repository at this point in the history
…d mid-event

This reverts afaa758 and replaces it with a more general
no-assert-during-events check. This is because there are other instances besides [inspect]
where this function can be called mid-event, and it wouldn't be convenient to add nested
'strict' parameters to multiple functions just to handle them.

Fixes #2750.

(cherry-picked from commit a1810bd)
  • Loading branch information
Vultraz committed Oct 7, 2018
1 parent 81494ce commit 0fbb01e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -71,6 +71,7 @@
* Fixed images with no alpha channel rendering incorrectly.
* Fixed unit selection not persisting between uses of Create Unit.
* Fixed assertion when undoing actions in a synced context.
* Fixed assertion when saving game events mid-event.

## Version 1.13.12
### Security fixes
Expand Down
22 changes: 16 additions & 6 deletions src/game_events/manager.cpp
Expand Up @@ -132,16 +132,26 @@ void manager::add_events(const config::const_child_itors& cfgs, const std::strin
}
}

void manager::write_events(config& cfg, bool strict) const
void manager::write_events(config& cfg) const
{
for(const handler_ptr& eh : event_handlers_->get_active()) {
if(eh && !eh->is_menu_item()) {
if(strict) {
assert(!eh->disabled());
}
if(!eh || eh->is_menu_item()) {
continue;
}

cfg.add_child("event", eh->get_config());;
// This function may be invoked mid-event, such as via [inspect] (the inspector writes
// the events to a local config) or if an out-of-sync error happens in MP. In that case,
// it's possible for the currently running event is already disabled. That would happen
// if it's a first-time-only event; those are disabled before their actions are run. In
// that case, skip disabled events. If invoked from outside an event, however, there
// should be no disabled events in the list, so assert if one is found.
if(eh->disabled() && is_event_running()) {
continue;
} else {
assert(!eh->disabled());
}

cfg.add_child("event", eh->get_config());;
}

cfg["unit_wml_ids"] = utils::join(unit_wml_ids_);
Expand Down
2 changes: 1 addition & 1 deletion src/game_events/manager.hpp
Expand Up @@ -68,7 +68,7 @@ class manager

void add_events(const config::const_child_itors& cfgs, const std::string& type = std::string());

void write_events(config& cfg, bool strict = true) const;
void write_events(config& cfg) const;

using event_func_t = std::function<void(game_events::manager&, handler_ptr&)>;
void execute_on_events(const std::string& event_id, event_func_t func);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/dialogs/gamestate_inspector.cpp
Expand Up @@ -509,7 +509,7 @@ const display_context& single_mode_controller::dc() const {
event_mode_controller::event_mode_controller(gamestate_inspector::controller& c)
: single_mode_controller(c)
{
single_mode_controller::events().write_events(events, false);
single_mode_controller::events().write_events(events);
}

void variable_mode_controller::show_list(tree_view_node& node)
Expand Down

0 comments on commit 0fbb01e

Please sign in to comment.