From f36caedb952020bc66806705616b7797e63c9ee4 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 3 Apr 2017 12:20:28 -0700 Subject: [PATCH] SDL: Fix race condition with audio thread when starting --- CHANGES | 1 + src/platform/sdl/main.c | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 55dcec3b9..ab001d332 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,7 @@ Bugfixes: - GBA Video: Fix wrong palette on 256-color sprites in OBJWIN - Windows: Fix VDir.rewind - SDL: Fix game crash check + - SDL: Fix race condition with audio thread when starting Misc: - Qt: Improved HiDPI support - Feature: Support ImageMagick 7 diff --git a/src/platform/sdl/main.c b/src/platform/sdl/main.c index 700d8f6c4..4e361d419 100644 --- a/src/platform/sdl/main.c +++ b/src/platform/sdl/main.c @@ -185,29 +185,31 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) { renderer->audio.samples = renderer->core->opts.audioBuffers; renderer->audio.sampleRate = 44100; - bool didFail = !mSDLInitAudio(&renderer->audio, &thread); + bool didFail = !mCoreThreadStart(&thread); if (!didFail) { #if SDL_VERSION_ATLEAST(2, 0, 0) mSDLSetScreensaverSuspendable(&renderer->events, renderer->core->opts.suspendScreensaver); mSDLSuspendScreensaver(&renderer->events); #endif - if (mCoreThreadStart(&thread)) { + if (mSDLInitAudio(&renderer->audio, &thread)) { renderer->runloop(renderer, &thread); mSDLPauseAudio(&renderer->audio); if (mCoreThreadHasCrashed(&thread)) { didFail = true; printf("The game crashed!\n"); } - mCoreThreadJoin(&thread); } else { didFail = true; - printf("Could not run game. Are you sure the file exists and is a compatible game?\n"); + printf("Could not initialize audio.\n"); } - #if SDL_VERSION_ATLEAST(2, 0, 0) mSDLResumeScreensaver(&renderer->events); mSDLSetScreensaverSuspendable(&renderer->events, false); #endif + + mCoreThreadJoin(&thread); + } else { + printf("Could not run game. Are you sure the file exists and is a compatible game?\n"); } renderer->core->unloadROM(renderer->core); return didFail;