From 4583e48c3d83f0278a86a88078be4d3a98ab21ce Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Tue, 23 Sep 2008 10:45:05 +0000 Subject: [PATCH] * lock playHandle mutex in mixer::clear() * moved implementation of mixer::removePlayHandle() from header to source-file * only delete play-handle in mixer::removePlayHandle() if it was found in playHandle vector (fixes crash when previewing a preset under high load) git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1698 0778d3d1-df1d-0410-868b-ea421aaaa00d --- include/mixer.h | 26 +------------------------- src/core/mixer.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/include/mixer.h b/include/mixer.h index ffed5b9ae..47997394e 100644 --- a/include/mixer.h +++ b/include/mixer.h @@ -243,31 +243,7 @@ public: return( FALSE ); } - void removePlayHandle( playHandle * _ph ) - { - // check thread affinity as we must not delete play-handles - // which were created in a thread different than mixer thread - if( _ph->affinityMatters() && - _ph->affinity() == QThread::currentThread() ) - { - lockPlayHandles(); - playHandleVector::iterator it = - qFind( m_playHandles.begin(), - m_playHandles.end(), _ph ); - if( it != m_playHandles.end() ) - { - m_playHandles.erase( it ); - } - unlockPlayHandles(); - delete _ph; - } - else - { - lockPlayHandlesToRemove(); - m_playHandlesToRemove.push_back( _ph ); - unlockPlayHandlesToRemove(); - } - } + void removePlayHandle( playHandle * _ph ); inline playHandleVector & playHandles( void ) { diff --git a/src/core/mixer.cpp b/src/core/mixer.cpp index a0ad15e5f..170363f56 100644 --- a/src/core/mixer.cpp +++ b/src/core/mixer.cpp @@ -735,6 +735,7 @@ const surroundSampleFrame * mixer::renderNextBuffer( void ) void mixer::clear( void ) { // TODO: m_midiClient->noteOffAll(); + lockPlayHandles(); lockPlayHandlesToRemove(); for( playHandleVector::iterator it = m_playHandles.begin(); it != m_playHandles.end(); ++it ) @@ -747,6 +748,7 @@ void mixer::clear( void ) } } unlockPlayHandlesToRemove(); + unlockPlayHandles(); } @@ -953,6 +955,34 @@ void mixer::restoreAudioDevice( void ) +void mixer::removePlayHandle( playHandle * _ph ) +{ + // check thread affinity as we must not delete play-handles + // which were created in a thread different than mixer thread + if( _ph->affinityMatters() && + _ph->affinity() == QThread::currentThread() ) + { + lockPlayHandles(); + playHandleVector::iterator it = + qFind( m_playHandles.begin(), + m_playHandles.end(), _ph ); + if( it != m_playHandles.end() ) + { + m_playHandles.erase( it ); + delete _ph; + } + unlockPlayHandles(); + } + else + { + lockPlayHandlesToRemove(); + m_playHandlesToRemove.push_back( _ph ); + unlockPlayHandlesToRemove(); + } +} + + + void mixer::removePlayHandles( track * _track ) { lockPlayHandles();