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.
This commit is contained in:
bjorn 2020-12-11 04:41:48 -07:00
parent 8ef50b5f6a
commit e887d46256
1 changed files with 12 additions and 8 deletions

View File

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