Fix crash when playing invalid sounds under wxOSX.

Sound ID 0 is not actually invalid, it is returned by
AudioServicesCreateSystemSoundID() when it fails to open the file and
currently we don't consider this to be an error. However, because we never
called AudioServicesDisposeSystemSoundID() for this sound ID, we continued to
receive the notifications from the callback registered by
AudioServicesAddSystemSoundCompletion() for it even after the corresponding
sound object was destroyed, resulting in crashes when playing it more than
once.

Fix this by keeping a separate flag indicating whether we're playing a sound
and always disposing of the sound if we are, even if ID is 0.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76323 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2014-04-12 22:56:13 +00:00
parent 719f6df326
commit 48b21dee76

View File

@ -47,12 +47,14 @@ protected:
SystemSoundID m_soundID;
wxString m_sndname; //file path
bool m_playing;
};
wxOSXAudioToolboxSoundData::wxOSXAudioToolboxSoundData(const wxString& fileName) :
m_soundID(NULL)
{
m_sndname = fileName;
m_playing = false;
}
wxOSXAudioToolboxSoundData::~wxOSXAudioToolboxSoundData()
@ -91,10 +93,10 @@ void wxOSXAudioToolboxSoundData::SoundCompleted()
void wxOSXAudioToolboxSoundData::DoStop()
{
if (m_soundID)
if ( m_playing )
{
m_playing = false;
AudioServicesDisposeSystemSoundID (m_soundID);
m_soundID = NULL;
wxSound::SoundStopped(this);
}
@ -115,11 +117,13 @@ bool wxOSXAudioToolboxSoundData::Play(unsigned flags)
bool sync = !(flags & wxSOUND_ASYNC);
m_playing = true;
AudioServicesPlaySystemSound(m_soundID);
if ( sync )
{
while( m_soundID )
while ( m_playing )
{
CFRunLoopRun();
}