From 453d348fdc2fed710eac3ec33aa2336562d107ab Mon Sep 17 00:00:00 2001 From: Nevyn Bengtsson Date: Fri, 6 Nov 2020 22:06:07 +0100 Subject: [PATCH] Stack trace when background thread crashes Without this, the error handler only prints the _main thread's error handler's_ stack trace --- src/api/l_thread.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/api/l_thread.c b/src/api/l_thread.c index d1b946ff..dec13a0b 100644 --- a/src/api/l_thread.c +++ b/src/api/l_thread.c @@ -23,12 +23,15 @@ static int threadRunner(void* data) { luax_register(L, lovrModules); lua_pop(L, 2); + lua_pushcfunction(L, luax_getstack); + int errhandler = lua_gettop(L); + if (!luaL_loadbuffer(L, thread->body->data, thread->body->size, "thread")) { for (uint32_t i = 0; i < thread->argumentCount; i++) { luax_pushvariant(L, &thread->arguments[i]); } - if (!lua_pcall(L, thread->argumentCount, 0, 0)) { + if (!lua_pcall(L, thread->argumentCount, 0, errhandler)) { mtx_lock(&thread->lock); thread->running = false; mtx_unlock(&thread->lock);