Stack trace when background thread crashes

Without this, the error handler only prints the _main thread's
error handler's_ stack trace
This commit is contained in:
Nevyn Bengtsson 2020-11-06 22:06:07 +01:00 committed by bjorn
parent e8db2f8187
commit 453d348fdc
1 changed files with 4 additions and 1 deletions

View File

@ -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);