From 73512ad38f62e530d73737740ae1d94b52b8b9c4 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Sat, 18 Oct 2014 08:32:14 -0500 Subject: [PATCH] Fix a race condition in our OpenSL ES audio backend. After calling enqueue the callback would fire before we had assigned g_mixer a value. This would cause a fun crash to happen. --- Source/Core/AudioCommon/OpenSLESStream.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Source/Core/AudioCommon/OpenSLESStream.cpp b/Source/Core/AudioCommon/OpenSLESStream.cpp index afbaa00cdd..e4e11652e4 100644 --- a/Source/Core/AudioCommon/OpenSLESStream.cpp +++ b/Source/Core/AudioCommon/OpenSLESStream.cpp @@ -45,7 +45,6 @@ static void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context) // which for this code example would indicate a programming error _assert_msg_(AUDIO, SL_RESULT_SUCCESS == result, "Couldn't enqueue audio stream."); - curBuffer ^= 1; // Switch buffer // Render to the fresh buffer g_mixer->Mix(reinterpret_cast(buffer[curBuffer]), BUFFER_SIZE_IN_SAMPLES); @@ -101,17 +100,14 @@ bool OpenSLESStream::Start() result = (*bqPlayerPlay)->SetPlayState(bqPlayerPlay, SL_PLAYSTATE_PLAYING); assert(SL_RESULT_SUCCESS == result); - // Render and enqueue a first buffer. (or should we just play the buffer empty?) - curBuffer = 0; - - result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer[curBuffer], sizeof(buffer[curBuffer])); - if (SL_RESULT_SUCCESS != result) - { - return false; - } - + // Render and enqueue a first buffer. curBuffer ^= 1; g_mixer = m_mixer; + + result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer[0], sizeof(buffer[0])); + if (SL_RESULT_SUCCESS != result) + return false; + return true; }