From 3c4e443ddc211b4ecdd2b990a3fa9b12b46efaf6 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 9 Jun 2017 12:16:31 +0200 Subject: Fixed handling Lua errors in nested callbacks (#3755) --- src/Bindings/LuaState.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/Bindings/LuaState.cpp') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index ca0a258d9..947e337fc 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -1454,8 +1454,12 @@ bool cLuaState::CallFunction(int a_NumResults) LOGWARNING("Error in %s calling function %s()", m_SubsystemName.c_str(), CurrentFunctionName.c_str()); // Remove the error handler and error message from the stack: - ASSERT(lua_gettop(m_LuaState) == 2); - lua_pop(m_LuaState, 2); + auto top = lua_gettop(m_LuaState); + if (top < 2) + { + LogStackValues(Printf("The Lua stack is in an unexpected state, expected at least two values there, but got %d", top).c_str()); + } + lua_pop(m_LuaState, std::min(2, top)); return false; } -- cgit v1.2.3