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.
@@ -38,10 +38,12 @@ 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);
+ if (error) {
thread->error = malloc(length + 1);
if (thread->error) {
memcpy(thread->error, error, length + 1);
@@ -50,6 +52,8 @@ static int threadRunner(void* data) {
.data.thread = { thread, thread->error }
});
}
+ }
+
thread->running = false;
mtx_unlock(&thread->lock);
lovrRelease(Thread, thread);
