From aa3dacc84bb1e229225268e68263395b4f0a63fa Mon Sep 17 00:00:00 2001 From: CPunch Date: Sun, 9 May 2021 00:58:10 -0500 Subject: [PATCH] Fixed stack issue with lEvents --- src/lua/LuaWrapper.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lua/LuaWrapper.hpp b/src/lua/LuaWrapper.hpp index 5d9d46a..d8e57bb 100644 --- a/src/lua/LuaWrapper.hpp +++ b/src/lua/LuaWrapper.hpp @@ -189,6 +189,11 @@ public: switch (event->type) { case EVENT_CALLBACK: { // make thread for this callback + if (!lua_checkstack(event->state, 1)) { + std::cout << "[FATAL] Failed to create new lua thread! out of memory!" << std::endl; + terminate(0); + } + lua_State *nThread = lua_newthread(event->state); // push the callable first, the push all the arguments @@ -197,9 +202,6 @@ public: // then call it :) yieldCall(nThread, nargs); - - // we can safely pop the thread off the stack now - lua_pop(event->state, 1); break; } case EVENT_WAIT: {