aboutsummaryrefslogtreecommitdiffstats
path: root/c_src/nif_helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'c_src/nif_helpers.c')
-rw-r--r--c_src/nif_helpers.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/c_src/nif_helpers.c b/c_src/nif_helpers.c
index f655497..0528b35 100644
--- a/c_src/nif_helpers.c
+++ b/c_src/nif_helpers.c
@@ -168,7 +168,13 @@ void* nif_create_main_thread(char* name)
st->mailbox = (nif_thread_mailbox*)enif_alloc(sizeof(nif_thread_mailbox));
TAILQ_INIT(st->mailbox);
+#ifdef __DARWIN__
+ // On OSX, SDL2 must run in the main thread, otherwise some operations
+ // will not work properly. For example, input events would not be received.
+ erl_drv_steal_main_thread(name, &(st->tid), nif_main_thread, st, NULL);
+#else
enif_thread_create(name, &(st->tid), nif_main_thread, st, NULL);
+#endif
return (void*)st;
}