From 48b21dee765b9f2cd5c492121eea8c97777ac234 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 12 Apr 2014 22:56:13 +0000 Subject: [PATCH] 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 --- src/osx/core/sound.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/osx/core/sound.cpp b/src/osx/core/sound.cpp index c467cb9ff4..0064ea3222 100644 --- a/src/osx/core/sound.cpp +++ b/src/osx/core/sound.cpp @@ -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(); }