Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/base
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2025-04-12 16:53:22 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2025-04-12 16:53:22 +1000
commit97ba073681b75af10cd0eab827a6aa98b77ea627 (patch)
treecc2a99a33822b08842060474b890672c20798300 /source/base
parentc6507aafab4ac86845b53b4b5e8dd4366a6571a5 (diff)
Fix multiple Lua patches of the same path not working correctly
Diffstat (limited to 'source/base')
-rw-r--r--source/base/StarAssets.cpp6
-rw-r--r--source/base/StarAssets.hpp2
2 files changed, 5 insertions, 3 deletions
diff --git a/source/base/StarAssets.cpp b/source/base/StarAssets.cpp
index 9742f9e..b6aeab9 100644
--- a/source/base/StarAssets.cpp
+++ b/source/base/StarAssets.cpp
@@ -969,8 +969,9 @@ ImageConstPtr Assets::readImage(String const& path) const {
auto& patchSource = pair.second;
auto patchStream = patchSource->read(patchPath);
if (patchPath.endsWith(".lua")) {
+ std::pair<AssetSource*, String> contextKey = make_pair(patchSource.get(), patchPath);
luaLocker.lock();
- LuaContextPtr& context = m_patchContexts[patchPath];
+ LuaContextPtr& context = m_patchContexts[contextKey];
if (!context) {
context = make_shared<LuaContext>(luaEngine->createContext());
context->load(patchStream, patchPath);
@@ -1042,9 +1043,10 @@ Json Assets::readJson(String const& path) const {
auto& patchSource = pair.second;
auto patchStream = patchSource->read(patchBasePath);
if (patchBasePath.endsWith(".lua")) {
+ std::pair<AssetSource*, String> contextKey = make_pair(patchSource.get(), patchBasePath);
RecursiveMutexLocker luaLocker(m_luaMutex);
// Kae: i don't like that lock. perhaps have a LuaEngine and patch context cache per worker thread later on?
- LuaContextPtr& context = m_patchContexts[patchBasePath];
+ LuaContextPtr& context = m_patchContexts[contextKey];
if (!context) {
context = make_shared<LuaContext>(as<LuaEngine>(m_luaEngine.get())->createContext());
context->load(patchStream, patchBasePath);
diff --git a/source/base/StarAssets.hpp b/source/base/StarAssets.hpp
index a8e4480..6cc8c16 100644
--- a/source/base/StarAssets.hpp
+++ b/source/base/StarAssets.hpp
@@ -331,7 +331,7 @@ private:
// Lua
RefPtr<RefCounter> m_luaEngine; // dumb but to avoid including Lua.hpp in here...
- mutable StringMap<LuaContextPtr> m_patchContexts;
+ mutable HashMap<pair<AssetSource*, String>, LuaContextPtr> m_patchContexts;
mutable RecursiveMutex m_luaMutex;
// Paths of all used asset sources, in load order.