Fix crash on audio settings change.

This commit is contained in:
Christian Speckner 2018-01-28 23:23:14 +01:00
parent 8c4faf122b
commit ae88a5b6b6
4 changed files with 27 additions and 7 deletions

View File

@ -40,6 +40,7 @@
"ratio": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"stdexcept": "cpp"
"stdexcept": "cpp",
"fstream": "cpp"
}
}

View File

@ -132,3 +132,15 @@ Int16* AudioQueue::dequeue(Int16* fragment)
return nextFragment;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void AudioQueue::closeSink(Int16* fragment)
{
lock_guard<mutex> guard(myMutex);
if (myFirstFragmentForDequeue && fragment)
throw new runtime_error("attempt to return unknown buffer on closeSink");
if (!myFirstFragmentForDequeue)
myFirstFragmentForDequeue = fragment;
}

View File

@ -86,15 +86,21 @@ class AudioQueue
Int16* enqueue(Int16* fragment = 0);
/**
* Dequeue a fragment for playback and return the played fragment. This may
* return 0 if there is no queued fragment to return (in this case, the returned
* fragment is not enqueued and must be passed in the next invocation).
*
* @param fragment The returned fragment. This must be empty on the first call (when
* there is nothing to return).
Dequeue a fragment for playback and return the played fragment. This may
return 0 if there is no queued fragment to return (in this case, the returned
fragment is not enqueued and must be passed in the next invocation).
@param fragment The returned fragment. This must be empty on the first call (when
there is nothing to return).
*/
Int16* dequeue(Int16* fragment = 0);
/**
Return the currently playing fragment without drawing a new one. This is called
if the sink is closed and prepares the queue to be reopened.
*/
void closeSink(Int16* fragment);
private:
// The size of an individual fragment (in stereo / mono samples)

View File

@ -143,6 +143,7 @@ void SoundSDL2::close()
mute(true);
if (myAudioQueue) myAudioQueue->closeSink(myCurrentFragment);
myAudioQueue = 0;
myCurrentFragment = 0;