From b4486229219fe0ebca0886c36d1163532df383cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Wed, 20 Nov 2024 20:42:11 +0100 Subject: [PATCH] Fix crash when a Lua tool Perform callback throws an error Broken since 00ec4e0754d1, when the Perform callback was added. It's a bad idea to pop return values that never got pushed because the function that was supposed to push them threw an error. --- src/lua/LuaTools.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lua/LuaTools.cpp b/src/lua/LuaTools.cpp index 68400bf3f..2cd02ce16 100644 --- a/src/lua/LuaTools.cpp +++ b/src/lua/LuaTools.cpp @@ -91,11 +91,14 @@ static int luaPerformWrapper(SimTool *tool, Simulation *sim, Particle *cpart, in lsi->Log(CommandInterface::LogError, "In perform func: " + LuaGetError()); lua_pop(L, 1); } - if (lua_isboolean(L, -1)) + else { - ok = lua_toboolean(L, -1); + if (lua_isboolean(L, -1)) + { + ok = lua_toboolean(L, -1); + } + lua_pop(L, 1); } - lua_pop(L, 1); } return ok; }