diff --git a/components/lua/luastate.cpp b/components/lua/luastate.cpp index 3cf6378f2f..26b832bdf9 100644 --- a/components/lua/luastate.cpp +++ b/components/lua/luastate.cpp @@ -386,7 +386,14 @@ namespace LuaUtil { auto iter = mCompiledScripts.find(path); if (iter != mCompiledScripts.end()) - return mSol.load(iter->second.as_string_view(), path, sol::load_mode::binary); + { + sol::load_result res = mSol.load(iter->second.as_string_view(), path, sol::load_mode::binary); + // Unless we have memory corruption issues, the bytecode is valid at this point, but loading might still + // fail because we've hit our Lua memory cap + if (!res.valid()) + throw std::runtime_error("Lua error: " + res.get()); + return res; + } sol::function res = loadFromVFS(path); mCompiledScripts[path] = res.dump(); return res;