From 8c5f85ca83907f31ba4532bbe0afae15a3986630 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 21 Mar 2012 14:49:29 -0700 Subject: [PATCH] Use a local variable to mark sound streams as finished while processing This avoids a race condition where the source can underrun while the final buffers are being queued and the sound can be detected as stopped --- apps/openmw/mwsound/openal_output.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index d41d692db6..ed7be21f63 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -251,6 +251,7 @@ void OpenAL_SoundStream::update(const float *pos) bool OpenAL_SoundStream::process() { + bool finished = mIsFinished; ALint processed, state; alGetSourcei(mSource, AL_SOURCE_STATE, &state); @@ -267,11 +268,11 @@ bool OpenAL_SoundStream::process() alSourceUnqueueBuffers(mSource, 1, &bufid); processed--; - if(mIsFinished) + if(finished) continue; got = mDecoder->read(data.data(), data.size()); - mIsFinished = (got < data.size()); + finished = (got < data.size()); if(got > 0) { alBufferData(bufid, mFormat, data.data(), got, mSampleRate); @@ -294,7 +295,8 @@ bool OpenAL_SoundStream::process() } } - return !mIsFinished; + mIsFinished = finished; + return !finished; } //