From b1caff97feebdd66f3022cde612e8ba0ddbabc91 Mon Sep 17 00:00:00 2001 From: Quentin Date: Wed, 21 Feb 2024 13:05:01 +0100 Subject: [PATCH] lua: fix enabling/disabling (#2745) --- src/lua/lua_manager.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lua/lua_manager.cpp b/src/lua/lua_manager.cpp index 33c3e637..3b315fff 100644 --- a/src/lua/lua_manager.cpp +++ b/src/lua/lua_manager.cpp @@ -180,10 +180,12 @@ namespace big const auto module_path = module->module_path(); // unload module + { std::lock_guard guard(m_disabled_module_lock); std::erase_if(m_disabled_modules, [module_id](auto& module) { return module_id == module->module_id(); }); + } const auto new_module_path = move_file_relative_to_folder(m_disabled_scripts_folder.get_path(), m_scripts_folder.get_path(), module_path); if (new_module_path) @@ -202,10 +204,12 @@ namespace big const auto module_path = module->module_path(); // unload module + { std::lock_guard guard(m_disabled_module_lock); std::erase_if(m_modules, [module_id](auto& module) { return module_id == module->module_id(); }); + } const auto new_module_path = move_file_relative_to_folder(m_scripts_folder.get_path(), m_disabled_scripts_folder.get_path(), module_path); if (new_module_path) @@ -219,10 +223,14 @@ namespace big void lua_manager::unload_module(rage::joaat_t module_id) { std::lock_guard guard(m_module_lock); - std::erase_if(m_modules, [module_id](auto& module) { return module_id == module->module_id(); }); + + std::lock_guard guard2(m_disabled_module_lock); + std::erase_if(m_disabled_modules, [module_id](auto& module) { + return module_id == module->module_id(); + }); } std::weak_ptr lua_manager::load_module(const std::filesystem::path& module_path) @@ -234,7 +242,7 @@ namespace big } const auto module_name = module_path.filename().string(); - const auto id = rage::joaat(module_name); + const auto id = rage::joaat(module_name); std::lock_guard guard(m_module_lock); for (const auto& module : m_modules) @@ -246,9 +254,9 @@ namespace big } } - const auto rel = relative(module_path, m_disabled_scripts_folder.get_path()); + const auto rel = relative(module_path, m_disabled_scripts_folder.get_path()); const auto is_disabled_module = !rel.empty() && rel.native()[0] != '.'; - const auto module = std::make_shared(module_path, m_scripts_folder, is_disabled_module); + const auto module = std::make_shared(module_path, m_scripts_folder, is_disabled_module); if (!module->is_disabled()) { module->load_and_call_script();