From 80015c3839f7b540afb4a10428ac311ef4d40bbb Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Fri, 18 Mar 2022 22:11:08 +0100 Subject: [PATCH] Fix event_handler --- src/client/game/scripting/lua/event_handler.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/client/game/scripting/lua/event_handler.cpp b/src/client/game/scripting/lua/event_handler.cpp index 6c9286bb..b57b1250 100644 --- a/src/client/game/scripting/lua/event_handler.cpp +++ b/src/client/game/scripting/lua/event_handler.cpp @@ -33,15 +33,16 @@ namespace scripting::lua this->merge_callbacks(); this->handle_endon_conditions(event); - for (auto i = tasks.begin(); i != tasks.end();) + for (auto i = 0; i < tasks.size();) { - if (i->event != event.name || i->entity != event.entity) + const auto task = tasks[i]; + if (task.event != event.name || task.entity != event.entity) { ++i; continue; } - if (!i->is_deleted) + if (!task.is_deleted) { if (!has_built_arguments) { @@ -49,12 +50,12 @@ namespace scripting::lua arguments = this->build_arguments(event); } - handle_error(i->callback(sol::as_args(arguments))); + handle_error(task.callback(sol::as_args(arguments))); } - if (i->is_volatile || i->is_deleted) + if (task.is_volatile || task.is_deleted) { - i = tasks.erase(i); + tasks.erase(tasks.begin() + i); } else { @@ -94,8 +95,8 @@ namespace scripting::lua callbacks_.access([&](task_list& tasks) { - merger(tasks); - new_callbacks_.access(merger); + merger(tasks); + new_callbacks_.access(merger); }); }