From 818ca18ebb8940999ed0d5b069d55ce66c81fc73 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Thu, 31 Jul 2014 05:12:35 +0200 Subject: [PATCH] ALStream: Actually fix issue referenced in prev commit This bug occured when starting playback of a stream, then immediately stopping it, loading a different source, and starting playback again. The real issue was that in stopStream(), the streaming thread had not even queued anything yet, so it first decoded some data, then started playing the source (which had already been stopped in the main thread), and then finally saw the term request and stopped. Instead stopping the source after the thread has definitely terminated fixed the problem. --- src/alstream.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/alstream.cpp b/src/alstream.cpp index 2b68c0b..d5b9bdf 100644 --- a/src/alstream.cpp +++ b/src/alstream.cpp @@ -213,8 +213,6 @@ void ALStream::stopStream() { threadTermReq = true; - AL::Source::stop(alSrc); - if (thread) { SDL_WaitThread(thread, 0); @@ -222,6 +220,11 @@ void ALStream::stopStream() needsRewind = true; } + /* Need to stop the source _after_ the thread has terminated, + * because it might have accidentally started it again before + * seeing the term request */ + AL::Source::stop(alSrc); + procFrames = 0; } @@ -298,6 +301,9 @@ void ALStream::streamData() bool firstBuffer = true; ALDataSource::Status status; + if (threadTermReq) + return; + if (needsRewind) { if (startOffset > 0) @@ -308,6 +314,9 @@ void ALStream::streamData() for (int i = 0; i < STREAM_BUFS; ++i) { + if (threadTermReq) + return; + AL::Buffer::ID buf = alBuf[i]; status = source->fillBuffer(buf);