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
actorid
Chris Robinson 13 years ago
parent 6a85ef1229
commit 8c5f85ca83

@ -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;
}
//

Loading…
Cancel
Save