From fa3e8ea74d5a8ada3678996f9e32d2deb8941e61 Mon Sep 17 00:00:00 2001 From: uramer Date: Sat, 24 May 2025 17:58:16 +0200 Subject: [PATCH 1/3] Prevent conflicts between UI layer insertions --- apps/openmw/mwlua/uibindings.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwlua/uibindings.cpp b/apps/openmw/mwlua/uibindings.cpp index 677a51a887..33380b8ea3 100644 --- a/apps/openmw/mwlua/uibindings.cpp +++ b/apps/openmw/mwlua/uibindings.cpp @@ -160,26 +160,31 @@ namespace MWLua else return LuaUtil::toLuaIndex(index); }; - layersTable["insertAfter"] = [context]( - std::string_view afterName, std::string_view name, const sol::object& opt) { + layersTable["insertAfter"] = [context](std::string afterName, std::string_view name, const sol::object& opt) { LuaUi::Layer::Options options; options.mInteractive = LuaUtil::getValueOrDefault(LuaUtil::getFieldOrNil(opt, "interactive"), true); - size_t index = LuaUi::Layer::indexOf(afterName); - if (index == LuaUi::Layer::count()) - throw std::logic_error(std::string("Layer not found")); - index++; context.mLuaManager->addAction( - [=, name = std::string(name)]() { LuaUi::Layer::insert(index, name, options); }, "Insert UI layer"); + [=]() { + size_t index = LuaUi::Layer::indexOf(afterName); + if (index == LuaUi::Layer::count()) + throw std::logic_error( + Misc::StringUtils::format("Couldn't insert after non-existent layer %s", afterName)); + LuaUi::Layer::insert(index + 1, name, options); + }, + "Insert after UI layer"); }; - layersTable["insertBefore"] = [context]( - std::string_view beforename, std::string_view name, const sol::object& opt) { + layersTable["insertBefore"] = [context](std::string beforeName, std::string_view name, const sol::object& opt) { LuaUi::Layer::Options options; options.mInteractive = LuaUtil::getValueOrDefault(LuaUtil::getFieldOrNil(opt, "interactive"), true); - size_t index = LuaUi::Layer::indexOf(beforename); - if (index == LuaUi::Layer::count()) - throw std::logic_error(std::string("Layer not found")); context.mLuaManager->addAction( - [=, name = std::string(name)]() { LuaUi::Layer::insert(index, name, options); }, "Insert UI layer"); + [=]() { + size_t index = LuaUi::Layer::indexOf(beforeName); + if (index == LuaUi::Layer::count()) + throw std::logic_error( + Misc::StringUtils::format("Couldn't insert before non-existent layer %s", beforeName)); + LuaUi::Layer::insert(index - 1, name, options); + }, + "Insert before UI layer"); }; sol::table layers = LuaUtil::makeReadOnly(layersTable); sol::table layersMeta = layers[sol::metatable_key]; From b7b6a41aecf46fce03205e650571986074eda6bc Mon Sep 17 00:00:00 2001 From: uramer Date: Sat, 24 May 2025 19:38:29 +0200 Subject: [PATCH 2/3] Bump API revision --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 708cebef6b..e153fce677 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,7 @@ message(STATUS "Configuring OpenMW...") set(OPENMW_VERSION_MAJOR 0) set(OPENMW_VERSION_MINOR 49) set(OPENMW_VERSION_RELEASE 0) -set(OPENMW_LUA_API_REVISION 74) +set(OPENMW_LUA_API_REVISION 75) set(OPENMW_POSTPROCESSING_API_REVISION 2) set(OPENMW_VERSION_COMMITHASH "") From 32169155bb92d8f1c4386237c4363055b2fa1430 Mon Sep 17 00:00:00 2001 From: uramer Date: Tue, 27 May 2025 11:56:16 +0000 Subject: [PATCH 3/3] Fix before insert index --- apps/openmw/mwlua/uibindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwlua/uibindings.cpp b/apps/openmw/mwlua/uibindings.cpp index 33380b8ea3..bc5581eb74 100644 --- a/apps/openmw/mwlua/uibindings.cpp +++ b/apps/openmw/mwlua/uibindings.cpp @@ -182,7 +182,7 @@ namespace MWLua if (index == LuaUi::Layer::count()) throw std::logic_error( Misc::StringUtils::format("Couldn't insert before non-existent layer %s", beforeName)); - LuaUi::Layer::insert(index - 1, name, options); + LuaUi::Layer::insert(index, name, options); }, "Insert before UI layer"); };