Game Events: fixed a few oversights in 056d7ac8f8
* Fixed assertion failure when removing single-use custom events. Not actually something broken, I just forgot to add a "not already disabled" check when doing so since I added that assertion in event_handler::disable. * Added a message to the aforementioned assertion. * Ensure handler cleanup actually happens when removing custom events. * Account for events with multiple names in cleanup.
This commit is contained in:
parent
3f646cc965
commit
2c12d1328b
2 changed files with 12 additions and 9 deletions
|
@ -57,11 +57,10 @@ event_handler::event_handler(const config& cfg, bool imi)
|
|||
|
||||
void event_handler::disable()
|
||||
{
|
||||
assert(!disabled_);
|
||||
assert(!disabled_ && "Trying to disable a disabled event. Shouldn't happen!");
|
||||
disabled_ = true;
|
||||
}
|
||||
|
||||
|
||||
void event_handler::handle_event(const queued_event& event_info, game_lua_kernel& lk)
|
||||
{
|
||||
if(disabled_) {
|
||||
|
|
|
@ -149,14 +149,15 @@ void event_handlers::remove_event_handler(const std::string& id)
|
|||
if(find_it != id_map_.end()) {
|
||||
handler_ptr handler = find_it->second.lock();
|
||||
|
||||
// Remove handler.
|
||||
if(handler) {
|
||||
if(handler && !handler->disabled()) {
|
||||
handler->disable();
|
||||
}
|
||||
|
||||
// Do this even if the lock failed.
|
||||
// The index by name will self-adjust later. No need to adjust it now.
|
||||
id_map_.erase(find_it);
|
||||
|
||||
// Remove handler from other lists.
|
||||
clean_up_expired_handlers(handler->get_config()["name"]);
|
||||
}
|
||||
|
||||
log_handlers();
|
||||
|
@ -171,10 +172,13 @@ void event_handlers::clean_up_expired_handlers(const std::string& event_name)
|
|||
|
||||
active_.erase(to_remove, active_.end());
|
||||
|
||||
// Then remove any now-unlockable weak_ptrs from tbe by-name list.
|
||||
get(event_name).remove_if(
|
||||
[](weak_handler_ptr ptr) { return ptr.expired(); }
|
||||
);
|
||||
// Then remove any now-unlockable weak_ptrs from the by-name list.
|
||||
// Might be more than one so we split.
|
||||
for(const std::string& name : utils::split(event_name)) {
|
||||
get(name).remove_if(
|
||||
[](weak_handler_ptr ptr) { return ptr.expired(); }
|
||||
);
|
||||
}
|
||||
|
||||
// And finally remove any now-unlockable weak_ptrs from the with-variables name list.
|
||||
dynamic_.remove_if(
|
||||
|
|
Loading…
Add table
Reference in a new issue