diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index 2b3ca786ca..2d25428ec1 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -191,15 +191,30 @@ LuaManager::~LuaManager() delete m_pLock; } +/* Keep track of Lua stack, and enforce that when we release Lua, the stack is + * back where it was when we locked it. */ +static int g_iStackCounts[32]; +static int g_iNumStackCounts = 0; Lua *LuaManager::Get() { m_pLock->Lock(); + if( g_iNumStackCounts < ARRAYSIZE(g_iStackCounts) ) + { + g_iStackCounts[g_iNumStackCounts] = lua_gettop(L); + } + ++g_iNumStackCounts; return L; } void LuaManager::Release( Lua *&p ) { ASSERT( p == L ); + ASSERT( g_iNumStackCounts != 0 ); + --g_iNumStackCounts; + if( g_iNumStackCounts < ARRAYSIZE(g_iStackCounts) ) + { + ASSERT( g_iStackCounts[g_iNumStackCounts] == lua_gettop(L) ); + } m_pLock->Unlock(); p = NULL; }