Commit 3c05ba56 authored by deuce's avatar deuce
Browse files

More hackery to ensure SDL_Init() is called from the main() function.

parent 88ca198e
......@@ -1882,7 +1882,11 @@ CIOLIBEXPORT enum ciolib_codepage CIOLIBCALL ciolib_getcodepage(void)
#endif
sem_t initsdl_sem;
sem_t initsdldone_sem;
sem_t startsdl_sem;
sem_t main_sem;
int initsdl_ret = -1;
struct main_args {
int argc;
char **argv;
......@@ -1897,6 +1901,7 @@ void main_stub(void *argptr)
args->ret = CIOLIB_main(args->argc, args->argv);
args->no_sdl = 1;
sem_post(&initsdl_sem);
sem_post(&startsdl_sem);
sem_post(&main_sem);
exit_sdl_con();
}
......@@ -1906,11 +1911,18 @@ int main(int argc, char **argv)
struct main_args ma = {argc, argv, -1, 0};
sem_init(&initsdl_sem, 0, 0);
sem_init(&initsdldone_sem, 0, 0);
sem_init(&startsdl_sem, 0, 0);
sem_init(&main_sem, 0, 0);
_beginthread(main_stub, 0, &ma);
sem_wait(&initsdl_sem);
if (!ma.no_sdl) {
sdl_video_event_thread(NULL);
initsdl_ret = init_sdl_video();
sem_post(&initsdldone_sem);
if (initsdl_ret != -1) {
sem_wait(&startsdl_sem);
sdl_video_event_thread(NULL);
}
}
sem_wait(&main_sem);
return ma.ret;
......
......@@ -561,6 +561,9 @@ CIOLIBEXPORT void CIOLIBCALL ansi_ciolib_setdoorway(int enable);
#if defined(__DARWIN__)
extern sem_t initsdl_sem;
extern sem_t main_sem;
extern sem_t startsdl_sem;
extern sem_t initsdldone_sem;
extern int initsdl_ret;
#endif
#endif
......
......@@ -372,7 +372,7 @@ int sdl_init(int mode)
fullscreen=1;
// Needs to be *after* bitmap_drv_init()
#if defined(__DARWIN__)
sem_post(&initsdl_sem);
sem_post(&startsdl_sem);
#else
_beginthread(sdl_video_event_thread, 0, NULL);
#endif
......@@ -1058,7 +1058,13 @@ void sdl_video_event_thread(void *data)
int sdl_initciolib(int mode)
{
#if defined(__DARWIN__)
sem_post(&initsdl_sem);
sem_wait(&initsdldone_sem);
if (initsdl_ret) {
#else
if(init_sdl_video()) {
#endif
fprintf(stderr,"SDL Video Initialization Failed\n");
return(-1);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment