From a6936b5649d30a8060a538edd6a2ecc028beaf2d Mon Sep 17 00:00:00 2001 From: mcc Date: Wed, 10 Jul 2019 19:20:43 -0400 Subject: [PATCH] Fix -DLOVR_ENABLE_THREAD=OFF compile l_event.c was processing a thread-related event and in the process using a thread struct, even when LOVR_ENABLE_THREAD is undefined and threads do not exist. I caused the thread event type to simply not exist when the thread module is not being built. Since the event is now only sometimes present, I put it at the end of the enum as slight protection against binary mismatches with dynamically loaded modules. --- src/api/l_event.c | 4 ++++ src/modules/event/event.c | 2 ++ src/modules/event/event.h | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/api/l_event.c b/src/api/l_event.c index 1a38d52b..17f159e1 100644 --- a/src/api/l_event.c +++ b/src/api/l_event.c @@ -9,7 +9,9 @@ const char* EventTypes[] = { [EVENT_QUIT] = "quit", [EVENT_FOCUS] = "focus", +#ifdef LOVR_ENABLE_THREAD [EVENT_THREAD_ERROR] = "threaderror", +#endif }; static LOVR_THREAD_LOCAL int pollRef; @@ -103,11 +105,13 @@ static int nextEvent(lua_State* L) { lua_pushboolean(L, event.data.boolean.value); return 2; +#ifdef LOVR_ENABLE_THREAD case EVENT_THREAD_ERROR: luax_pushtype(L, Thread, event.data.thread.thread); lua_pushstring(L, event.data.thread.error); lovrRelease(Thread, event.data.thread.thread); return 3; +#endif case EVENT_CUSTOM: for (uint32_t i = 0; i < event.data.custom.count; i++) { diff --git a/src/modules/event/event.c b/src/modules/event/event.c index 75f92608..10407053 100644 --- a/src/modules/event/event.c +++ b/src/modules/event/event.c @@ -37,9 +37,11 @@ void lovrEventPump() { } void lovrEventPush(Event event) { +#ifdef LOVR_ENABLE_THREAD if (event.type == EVENT_THREAD_ERROR) { lovrRetain(event.data.thread.thread); } +#endif arr_push(&state.events, event); } diff --git a/src/modules/event/event.h b/src/modules/event/event.h index b0956dfd..64917434 100644 --- a/src/modules/event/event.h +++ b/src/modules/event/event.h @@ -10,8 +10,10 @@ struct Thread; typedef enum { EVENT_QUIT, EVENT_FOCUS, + EVENT_CUSTOM, +#ifdef LOVR_ENABLE_THREAD EVENT_THREAD_ERROR, - EVENT_CUSTOM +#endif } EventType; typedef enum {