From ba4d3d31a63afc4054347d5125ef0abccbfa4faf Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 12 Apr 2014 22:56:21 +0000 Subject: [PATCH] Add error handling to wxSound under wxOSX. Don't assume that we can open any file as a sound, check for the return value from AudioServicesCreateSystemSoundID(). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76325 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/core/sound.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/osx/core/sound.cpp b/src/osx/core/sound.cpp index 0064ea3222..195fe4fb4a 100644 --- a/src/osx/core/sound.cpp +++ b/src/osx/core/sound.cpp @@ -112,7 +112,13 @@ bool wxOSXAudioToolboxSoundData::Play(unsigned flags) CFStringNormalize(cfMutableString,kCFStringNormalizationFormD); wxCFRef url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false)); - AudioServicesCreateSystemSoundID(url, &m_soundID); + OSStatus err = AudioServicesCreateSystemSoundID(url, &m_soundID); + if ( err != 0 ) + { + wxLogError(_("Failed to load sound from \"%s\" (error %d)."), m_sndname, err); + return false; + } + AudioServicesAddSystemSoundCompletion( m_soundID, CFRunLoopGetCurrent(), NULL, wxOSXAudioToolboxSoundData::CompletionCallback, (void *) this ); bool sync = !(flags & wxSOUND_ASYNC);