From ecff80fcd1607ea1b84bd15cfcd1c33c0c5f1a87 Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Tue, 18 Aug 2020 20:51:08 +0200 Subject: [PATCH] Fix for crash when using the JACK backend and quickly reconfiguring. Need to ensure that JACK callbacks see the running flag as false after being stopped. Use a QMutex for this. Signed-off-by: Hans Petter Selasky --- linux/sound.cpp | 3 +++ src/soundbase.cpp | 10 +++++----- src/soundbase.h | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/linux/sound.cpp b/linux/sound.cpp index 3db291f7a9..7ea475a91a 100755 --- a/linux/sound.cpp +++ b/linux/sound.cpp @@ -240,6 +240,9 @@ int CSound::process ( jack_nframes_t nframes, void* arg ) CSound* pSound = static_cast ( arg ); int i; + // make sure we are locked during execution + QMutexLocker locker(&pSound->MutexAudioProcessCb); + if ( pSound->IsRunning() && ( nframes == static_cast ( pSound->iJACKBufferSizeMono ) ) ) { // get input data pointer diff --git a/src/soundbase.cpp b/src/soundbase.cpp index 5807479c37..18b2870f5d 100755 --- a/src/soundbase.cpp +++ b/src/soundbase.cpp @@ -75,15 +75,15 @@ void CSoundBase::Stop() // set flag so that thread can leave the main loop bRun = false; - // give thread some time to terminate - if ( !bIsCallbackAudioInterface ) - { - wait ( 5000 ); - } + // drain the audio process callback + QMutexLocker locker(&MutexAudioProcessCb); } void CSoundBase::run() { + // make sure we are locked during execution + QMutexLocker locker(&MutexAudioProcessCb); + // main loop of working thread while ( bRun ) { diff --git a/src/soundbase.h b/src/soundbase.h index ab588a4678..562482a238 100755 --- a/src/soundbase.h +++ b/src/soundbase.h @@ -26,6 +26,7 @@ #include #include +#include #ifndef HEADLESS # include #endif @@ -137,6 +138,7 @@ class CSoundBase : public QThread void run(); bool bRun; + QMutex MutexAudioProcessCb; void ParseMIDIMessage ( const CVector& vMIDIPaketBytes );