From 256c3dbc47130a5e282bb306ceb117359729d151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 16 Oct 2015 21:35:55 +0200 Subject: Steal the main thread on OSX Should fix issues with events not being handled properly, and possibly other things. Taken from Erlang's wx, which is proven to work. The function used is unfortunately undocumented. Not 100% sure everything is good with just that, it looks good enough on my VM, but I still have issues probably due to trying this on a VM. --- c_src/nif_helpers.c | 6 ++++++ 1 file changed, 6 insertions(+) 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; } -- cgit v1.2.3