Fix simulator crashing on MacOS

Event handling must happen on the main
thread for MacOS.

Not sure if button_queue_wait is the
best place for doing the SDL event
polling, but seems to work ok.

Change-Id: If928282df84bdd74e24a48afd7dbc4c4bfcc49e2
This commit is contained in:
Christian Soffke 2023-08-14 21:15:50 +02:00 committed by Solomon Peachy
parent 1745b74576
commit f1010005b0
5 changed files with 44 additions and 0 deletions

View file

@ -307,6 +307,15 @@ static bool event_handler(SDL_Event *event)
return false;
}
#ifdef __APPLE__
void handle_sdl_events(void)
{
SDL_Event event;
while(SDL_PollEvent(&event))
event_handler(&event);
}
#endif
void gui_message_loop(void)
{
SDL_Event event;

View file

@ -28,6 +28,10 @@
extern int sdl_app_has_input_focus;
#ifdef __APPLE__
void handle_sdl_events(void);
#endif
bool button_hold(void);
#undef button_init_device
void button_init_device(void);

View file

@ -138,6 +138,7 @@ static void sdl_window_setup(void)
}
}
#ifndef __APPLE__ /* MacOS requires events to be handled on main thread */
/*
* This thread will read the buttons in an interrupt like fashion, and
* also initializes SDL_INIT_VIDEO and the surfaces
@ -205,6 +206,7 @@ static int sdl_event_thread(void * param)
#endif
return 0;
}
#endif
static bool quitting;
@ -270,11 +272,13 @@ void system_init(void)
sdl_window_setup();
#endif
#ifndef __APPLE__ /* MacOS requires events to be handled on main thread */
s = SDL_CreateSemaphore(0); /* 0-count so it blocks */
evt_thread = SDL_CreateThread(sdl_event_thread, NULL, s);
SDL_SemWait(s);
/* cleanup */
SDL_DestroySemaphore(s);
#endif
}