From c0fb1402575f0501d08ea19fa31b3f7623f090e1 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Fri, 1 Jun 2018 12:53:26 -0400 Subject: [PATCH] Fix crashes in resampling of capture during recording --- src/AudioIO.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/AudioIO.cpp b/src/AudioIO.cpp index 245411e4e..c81647989 100644 --- a/src/AudioIO.cpp +++ b/src/AudioIO.cpp @@ -4029,7 +4029,11 @@ void AudioIO::FillBuffers() // discard some samples from the ring buffers. size_t size = floor( mRecordingSchedule.ToDiscard() * mRate ); - discarded = mCaptureBuffers[i]->Discard(size); + + // The ring buffer might have grown concurrently -- don't discard more + // than the "avail" value noted above. + discarded = mCaptureBuffers[i]->Discard(std::min(avail, size)); + if (discarded < size) // We need to visit this again to complete the // discarding. @@ -4053,6 +4057,7 @@ void AudioIO::FillBuffers() } } + wxASSERT(discarded <= avail); size_t toGet = avail - discarded; SampleBuffer temp; size_t size;