X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Finit.c;h=8c6c7e12e1d6d7010cb9fdfea0e03a15dba24c9c;hp=8c0f26e3ede53fd49e6feccfa6ed995f635d7e54;hb=381c9767a6a124feb2139051bace01eed817b03d;hpb=746d91a67b5059c607e8e6bd0453e6e0738ffe45 diff --git a/src/init.c b/src/init.c index 8c0f26e3..8c6c7e12 100644 --- a/src/init.c +++ b/src/init.c @@ -6351,8 +6351,44 @@ void OpenAll(void) #endif } +static boolean WaitForApiThreads(void) +{ + unsigned int thread_delay = 0; + unsigned int thread_delay_value = 10000; + + if (program.api_thread_count == 0) + return TRUE; + + // deactivate global animations (not accessible in game state "loading") + setup.toons = FALSE; + + // set game state to "loading" to be able to show busy animation + SetGameStatus(GAME_MODE_LOADING); + + ResetDelayCounter(&thread_delay); + + // wait for threads to finish (and fail on timeout) + while (program.api_thread_count > 0) + { + if (DelayReached(&thread_delay, thread_delay_value)) + { + Error("failed waiting for threads - TIMEOUT"); + + return FALSE; + } + + UPDATE_BUSY_STATE(); + + Delay(20); + } + + return TRUE; +} + void CloseAllAndExit(int exit_value) { + WaitForApiThreads(); + StopSounds(); FreeAllSounds(); FreeAllMusic();