From 0e0b4d46a40e32ee72415f843ed6e5dda46e66aa Mon Sep 17 00:00:00 2001 From: Quentin Date: Sat, 29 Jul 2023 11:22:04 +0200 Subject: [PATCH] fix(lua): fix script array iterator being potentially invalidated while iterating due to new scripts that could be added and the vector getting reallocated due to it. (#1883) --- src/lua/lua_module.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lua/lua_module.cpp b/src/lua/lua_module.cpp index 5b1da583..d48844b7 100644 --- a/src/lua/lua_module.cpp +++ b/src/lua/lua_module.cpp @@ -231,8 +231,11 @@ namespace big { std::lock_guard guard(m_registered_scripts_mutex); - for (auto& script : m_registered_scripts) + const auto script_count = m_registered_scripts.size(); + for (size_t i = 0; i < script_count; i++) { + const auto script = m_registered_scripts[i].get(); + if (script->is_enabled()) { script->tick();