From e887d4625673f39d9c33c0a56ce874f0e5f8c1d7 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 11 Dec 2020 04:41:48 -0700 Subject: [PATCH] Fix crash on non-string thread errors; Non-string errors are currently ignored. This is consistent with love, and is pretty obscure, but maybe it can be improved at some point. --- src/api/l_thread.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/api/l_thread.c b/src/api/l_thread.c index 1276aa07..8e5074e1 100644 --- a/src/api/l_thread.c +++ b/src/api/l_thread.c @@ -38,18 +38,22 @@ static int threadRunner(void* data) { } } + mtx_lock(&thread->lock); + // Error handling size_t length; const char* error = lua_tolstring(L, -1, &length); - mtx_lock(&thread->lock); - thread->error = malloc(length + 1); - if (thread->error) { - memcpy(thread->error, error, length + 1); - lovrEventPush((Event) { - .type = EVENT_THREAD_ERROR, - .data.thread = { thread, thread->error } - }); + if (error) { + thread->error = malloc(length + 1); + if (thread->error) { + memcpy(thread->error, error, length + 1); + lovrEventPush((Event) { + .type = EVENT_THREAD_ERROR, + .data.thread = { thread, thread->error } + }); + } } + thread->running = false; mtx_unlock(&thread->lock); lovrRelease(Thread, thread);