SDL: Fix race condition with audio thread when starting

This commit is contained in:
Vicki Pfau 2017-04-03 12:20:28 -07:00
parent 0191bb0768
commit f36caedb95
2 changed files with 8 additions and 5 deletions

View File

@ -16,6 +16,7 @@ Bugfixes:
- GBA Video: Fix wrong palette on 256-color sprites in OBJWIN - GBA Video: Fix wrong palette on 256-color sprites in OBJWIN
- Windows: Fix VDir.rewind - Windows: Fix VDir.rewind
- SDL: Fix game crash check - SDL: Fix game crash check
- SDL: Fix race condition with audio thread when starting
Misc: Misc:
- Qt: Improved HiDPI support - Qt: Improved HiDPI support
- Feature: Support ImageMagick 7 - Feature: Support ImageMagick 7

View File

@ -185,29 +185,31 @@ int mSDLRun(struct mSDLRenderer* renderer, struct mArguments* args) {
renderer->audio.samples = renderer->core->opts.audioBuffers; renderer->audio.samples = renderer->core->opts.audioBuffers;
renderer->audio.sampleRate = 44100; renderer->audio.sampleRate = 44100;
bool didFail = !mSDLInitAudio(&renderer->audio, &thread); bool didFail = !mCoreThreadStart(&thread);
if (!didFail) { if (!didFail) {
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
mSDLSetScreensaverSuspendable(&renderer->events, renderer->core->opts.suspendScreensaver); mSDLSetScreensaverSuspendable(&renderer->events, renderer->core->opts.suspendScreensaver);
mSDLSuspendScreensaver(&renderer->events); mSDLSuspendScreensaver(&renderer->events);
#endif #endif
if (mCoreThreadStart(&thread)) { if (mSDLInitAudio(&renderer->audio, &thread)) {
renderer->runloop(renderer, &thread); renderer->runloop(renderer, &thread);
mSDLPauseAudio(&renderer->audio); mSDLPauseAudio(&renderer->audio);
if (mCoreThreadHasCrashed(&thread)) { if (mCoreThreadHasCrashed(&thread)) {
didFail = true; didFail = true;
printf("The game crashed!\n"); printf("The game crashed!\n");
} }
mCoreThreadJoin(&thread);
} else { } else {
didFail = true; 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) #if SDL_VERSION_ATLEAST(2, 0, 0)
mSDLResumeScreensaver(&renderer->events); mSDLResumeScreensaver(&renderer->events);
mSDLSetScreensaverSuspendable(&renderer->events, false); mSDLSetScreensaverSuspendable(&renderer->events, false);
#endif #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); renderer->core->unloadROM(renderer->core);
return didFail; return didFail;