Game Events/Manager: skip disabled assertion if write_events is called mid-event

This reverts afaa75842c 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.
This commit is contained in:
Charles Dang 2018-04-11 13:08:27 +11:00
parent b0f767bdb5
commit a1810bde32
4 changed files with 20 additions and 9 deletions

View file

@ -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

View file

@ -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());
}
cfg.add_child("event", eh->get_config());;
if(!eh || eh->is_menu_item()) {
continue;
}
// 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_);

View file

@ -68,7 +68,7 @@ public:
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);

View file

@ -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)