ivansafrin/Polycode — pull request #150 by mcclure (2013-02-11 10:08:56+00:00)
Title: Lua stack overflows, crashing non-luaJIT player 100% of time 

Two problems.

1. luaL_newmetatable leaves behind an item on the stack, however, you were not balancing this with a lua_pop().

2. There is a call in LuaEventHandler::handleEvent to lua_getfield (L, LUA_GLOBALSINDEX, "__customError");. This serves no purpose, and leaves an unused value on the stack which is never removed. There's a freaky, unsafe settop() to work around the resulting stack leak.

Problem (1) was dumping so much junk on the stack that in non-luaJIT builds, I was getting heap corruption and it was impossible to launch the player.