diff --git a/components/lua/luastate.cpp b/components/lua/luastate.cpp index d8899a2634..9af617020e 100644 --- a/components/lua/luastate.cpp +++ b/components/lua/luastate.cpp @@ -126,11 +126,14 @@ namespace LuaUtil id = self->mActiveScriptIdStack.back(); bigAllocDelta = nsize; } - if (id.mContainer) + if (id.mIndex >= 0) { if (static_cast(id.mIndex) >= self->mMemoryUsage.size()) self->mMemoryUsage.resize(id.mIndex + 1); self->mMemoryUsage[id.mIndex] += bigAllocDelta; + } + if (id.mContainer) + { id.mContainer->addMemoryUsage(id.mIndex, bigAllocDelta); if (newPtr && nsize > smallAllocSize) self->mBigAllocOwners.emplace(newPtr, AllocOwner{ id.mContainer->mThis, id.mIndex }); diff --git a/components/lua/luastate.hpp b/components/lua/luastate.hpp index b0e173d67e..a41a29d283 100644 --- a/components/lua/luastate.hpp +++ b/components/lua/luastate.hpp @@ -23,7 +23,7 @@ namespace LuaUtil struct ScriptId { ScriptsContainer* mContainer = nullptr; - int mIndex; // index in LuaUtil::ScriptsConfiguration + int mIndex = -1; // index in LuaUtil::ScriptsConfiguration }; struct LuaStateSettings