Skip to content
Snippets Groups Projects
Commit 14ede244 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Fix up exit codes on macOS

The issue was that the various semaphores and mutexes weren't being
initialized at all when sdl_initconio() wasn't called... so starting
the event thread and telling it to stop would access uncreated
semaphores and mutexes.

Split out the init, and be sure to call it before exiting.
parent ba376305
Branches
Tags
No related merge requests found
Pipeline #6166 passed
...@@ -2028,8 +2028,8 @@ void main_stub(void *argptr) ...@@ -2028,8 +2028,8 @@ void main_stub(void *argptr)
args->ret = CIOLIB_main(args->argc, args->argv); args->ret = CIOLIB_main(args->argc, args->argv);
args->no_sdl = 1; args->no_sdl = 1;
sem_post(&startsdl_sem); sem_post(&startsdl_sem);
sem_post(&main_sem);
exit_sdl_con(); exit_sdl_con();
sem_post(&main_sem);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
......
...@@ -69,6 +69,7 @@ int sdl_init_good=0; ...@@ -69,6 +69,7 @@ int sdl_init_good=0;
pthread_mutex_t sdl_keylock; pthread_mutex_t sdl_keylock;
sem_t sdl_key_pending; sem_t sdl_key_pending;
static unsigned int sdl_pending_mousekeys=0; static unsigned int sdl_pending_mousekeys=0;
static bool sdl_sync_initialized;
struct sdl_keyvals { struct sdl_keyvals {
int keysym int keysym
...@@ -193,6 +194,7 @@ const struct sdl_keyvals sdl_keyval[] = ...@@ -193,6 +194,7 @@ const struct sdl_keyvals sdl_keyval[] =
void sdl_video_event_thread(void *data); void sdl_video_event_thread(void *data);
static void setup_surfaces(struct video_stats *vs); static void setup_surfaces(struct video_stats *vs);
static int sdl_initsync(void);
static void sdl_user_func(int func, ...) static void sdl_user_func(int func, ...)
{ {
...@@ -294,10 +296,9 @@ void exit_sdl_con(void) ...@@ -294,10 +296,9 @@ void exit_sdl_con(void)
{ {
// Avoid calling exit(0) from an atexit() function... // Avoid calling exit(0) from an atexit() function...
ciolib_reaper = 0; ciolib_reaper = 0;
if (sdl_init_good) if (!sdl_sync_initialized)
sdl_user_func_ret(SDL_USEREVENT_QUIT); sdl_initsync();
else sdl_user_func_ret(SDL_USEREVENT_QUIT);
exit(0);
} }
void sdl_copytext(const char *text, size_t buflen) void sdl_copytext(const char *text, size_t buflen)
...@@ -1030,7 +1031,7 @@ void sdl_video_event_thread(void *data) ...@@ -1030,7 +1031,7 @@ void sdl_video_event_thread(void *data)
if (sdl_init_good) if (sdl_init_good)
sdl_add_key(CIO_KEY_QUIT, &cvstat); sdl_add_key(CIO_KEY_QUIT, &cvstat);
else else
exit(0); return;
} }
break; break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
...@@ -1273,7 +1274,8 @@ void sdl_video_event_thread(void *data) ...@@ -1273,7 +1274,8 @@ void sdl_video_event_thread(void *data)
return; return;
} }
int sdl_initciolib(int mode) static int
sdl_initsync(void)
{ {
#if defined(__DARWIN__) #if defined(__DARWIN__)
if (initsdl_ret) { if (initsdl_ret) {
...@@ -1291,6 +1293,14 @@ int sdl_initciolib(int mode) ...@@ -1291,6 +1293,14 @@ int sdl_initciolib(int mode)
pthread_mutex_init(&win_mutex, NULL); pthread_mutex_init(&win_mutex, NULL);
pthread_mutex_init(&sdl_keylock, NULL); pthread_mutex_init(&sdl_keylock, NULL);
pthread_mutex_init(&sdl_mode_mutex, NULL); pthread_mutex_init(&sdl_mode_mutex, NULL);
sdl_sync_initialized = true;
return 0;
}
int sdl_initciolib(int mode)
{
if (sdl_initsync() == -1)
return -1;
return(sdl_init(mode)); return(sdl_init(mode));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment