From b09158220f6adc205f90192d7225d53f07d0e417 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Fri, 22 Nov 2019 23:37:17 -0500 Subject: [PATCH] Fix crash if error happens in ctypeDraw lua function --- src/lua/LuaScriptInterface.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 48f4847f6..1ddabe85d 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -2432,6 +2432,7 @@ void LuaScriptInterface::initElementsAPI() SETCONST(l, PROP_LIFE_KILL_DEC); SETCONST(l, PROP_SPARKSETTLE); SETCONST(l, PROP_NOAMBHEAT); + lua_pushinteger(l, 0); lua_setfield(l, -2, "PROP_DRAWONCTYPE"); SETCONST(l, PROP_NOCTYPEDRAW); SETCONST(l, FLAG_STAGNANT); SETCONST(l, FLAG_SKIPMOVE); @@ -2696,9 +2697,13 @@ static bool luaCtypeDrawWrapper(CTYPEDRAW_FUNC_ARGS) if (lua_pcall(luacon_ci->l, 3, 1, 0)) { luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); + lua_pop(luacon_ci->l, 1); + } + else + { + ret = luaL_optinteger(luacon_ci->l, -1, 0); + lua_pop(luacon_ci->l, 1); } - ret = luaL_optinteger(luacon_ci->l, -1, 0); - lua_pop(luacon_ci->l, 1); } return ret; }