diff --git a/apps/openmw/mwlua/luamanagerimp.cpp b/apps/openmw/mwlua/luamanagerimp.cpp index f695bd294e..15a172388d 100644 --- a/apps/openmw/mwlua/luamanagerimp.cpp +++ b/apps/openmw/mwlua/luamanagerimp.cpp @@ -166,6 +166,10 @@ namespace MWLua mObjectLists.update(); + for (auto scripts : mQueuedAutoStartedScripts) + scripts->addAutoStartedScripts(); + mQueuedAutoStartedScripts.clear(); + std::erase_if(mActiveLocalScripts, [](const LocalScripts* l) { return l->getPtrOrEmpty().isEmpty() || l->getPtrOrEmpty().mRef->isDeleted(); }); @@ -343,7 +347,7 @@ namespace MWLua if (!localScripts) { localScripts = createLocalScripts(ptr); - localScripts->addAutoStartedScripts(); + mQueuedAutoStartedScripts.push_back(localScripts); } mActiveLocalScripts.insert(localScripts); mEngineEvents.addToQueue(EngineEvents::OnActive{ getId(ptr) }); @@ -459,7 +463,7 @@ namespace MWLua if (!autoStartConf.empty()) { localScripts = createLocalScripts(ptr, std::move(autoStartConf)); - localScripts->addAutoStartedScripts(); // TODO: put to a queue and apply on next `update()` + mQueuedAutoStartedScripts.push_back(localScripts); } } if (localScripts) diff --git a/apps/openmw/mwlua/luamanagerimp.hpp b/apps/openmw/mwlua/luamanagerimp.hpp index e82c503c3a..22745fb90a 100644 --- a/apps/openmw/mwlua/luamanagerimp.hpp +++ b/apps/openmw/mwlua/luamanagerimp.hpp @@ -176,6 +176,7 @@ namespace MWLua MenuScripts mMenuScripts{ &mLua }; GlobalScripts mGlobalScripts{ &mLua }; std::set mActiveLocalScripts; + std::vector mQueuedAutoStartedScripts; ObjectLists mObjectLists; MWWorld::Ptr mPlayer;