From 40f277abfd0186d996e732c450e137ff216c6366 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Mon, 21 Mar 2022 21:48:22 +0100 Subject: [PATCH] Hopefully fix event_handler --- .../game/scripting/lua/event_handler.cpp | 28 ++++++++++--------- .../game/scripting/lua/event_handler.hpp | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/client/game/scripting/lua/event_handler.cpp b/src/client/game/scripting/lua/event_handler.cpp index b57b1250..d433fd18 100644 --- a/src/client/game/scripting/lua/event_handler.cpp +++ b/src/client/game/scripting/lua/event_handler.cpp @@ -33,29 +33,31 @@ namespace scripting::lua this->merge_callbacks(); this->handle_endon_conditions(event); - for (auto i = 0; i < tasks.size();) + for (auto i = tasks.begin(); i != tasks.end();) { - const auto task = tasks[i]; - if (task.event != event.name || task.entity != event.entity) + if (i->is_deleted) + { + i = tasks.erase(i); + continue; + } + + if (i->event != event.name || i->entity != event.entity) { ++i; continue; } - if (!task.is_deleted) + if (!has_built_arguments) { - if (!has_built_arguments) - { - has_built_arguments = true; - arguments = this->build_arguments(event); - } - - handle_error(task.callback(sol::as_args(arguments))); + has_built_arguments = true; + arguments = this->build_arguments(event); } - if (task.is_volatile || task.is_deleted) + handle_error(i->callback(sol::as_args(arguments))); + + if (i->is_volatile || i->is_deleted) { - tasks.erase(tasks.begin() + i); + i = tasks.erase(i); } else { diff --git a/src/client/game/scripting/lua/event_handler.hpp b/src/client/game/scripting/lua/event_handler.hpp index 981392e7..99009017 100644 --- a/src/client/game/scripting/lua/event_handler.hpp +++ b/src/client/game/scripting/lua/event_handler.hpp @@ -44,7 +44,7 @@ namespace scripting::lua sol::state& state_; std::atomic_int64_t current_listener_id_ = 0; - using task_list = std::vector; + using task_list = std::list; utils::concurrency::container new_callbacks_; utils::concurrency::container callbacks_;