Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does AudioServicesCreateSystemSoundID throw an exception internally but return 0 as an error code?

I’m running an iOS program in the 4.3.2, 5.0, and 5.1 Simulators, and I’m hitting a weird internal exception in AudioToolbox. I have a breakpoint set in Xcode (Xcode 4.3.1, running on 10.7.3) for all exceptions, and the debugger is breaking during a call to AudioServicesCreateSystemSoundID():

SystemSoundID soundID;
OSStatus errorCode = AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
                  // ^ boom. ^

The backtrace:

(lldb) bt
* thread #1: tid = 0x1f03, 0x9000e230 libc++abi.dylib`__cxa_throw, stop reason = breakpoint 1.2
frame #0: 0x9000e230 libc++abi.dylib`__cxa_throw
frame #1: 0x00144193 AudioToolbox`ID3ParserHandle::ID3ParserHandle(void*, long (*)(void*, unsigned long, unsigned long, unsigned long, void**, unsigned long*)) + 259
frame #2: 0x001442de AudioToolbox`ID3ParserOpen + 62
frame #3: 0x0006c0e7 AudioToolbox`MPEGAudioFile::ParseID3Tags() + 87
frame #4: 0x0006c2ba AudioToolbox`MPEGAudioFile::ParseAudioFile() + 26
frame #5: 0x00015153 AudioToolbox`AudioFileOpenWithCallbacks + 371
frame #6: 0x00027020 AudioToolbox`_ZL15VerifyAndMapURLPK7__CFURLRx + 448
frame #7: 0x00026d85 AudioToolbox`_ZL18ActionDataToServerPK7__CFURLm + 933
frame #8: 0x000da26b AudioToolbox`AudioServicesCreateSystemSoundID + 235
frame #9: 0x00005be1 app`-[SoundsViewController playSoundForPath:] + 257 at SoundsViewController.m:161
frame #10: 0x00005a99 app`-[SoundsViewController tableView:didSelectRowAtIndexPath:] + 777 at SoundsViewController.m:129
frame #11: 0x0029db68 UIKit`-[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
frame #12: 0x00293b05 UIKit`-[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
frame #13: 0x009ad79e Foundation`__NSFireDelayedPerform + 441
frame #14: 0x00fb58c3 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
frame #15: 0x00fb6e74 CoreFoundation`__CFRunLoopDoTimer + 1220
frame #16: 0x00f132c9 CoreFoundation`__CFRunLoopRun + 1817
frame #17: 0x00f12840 CoreFoundation`CFRunLoopRunSpecific + 208
frame #18: 0x00f12761 CoreFoundation`CFRunLoopRunInMode + 97
frame #19: 0x01f6b1c4 GraphicsServices`GSEventRunModal + 217
frame #20: 0x01f6b289 GraphicsServices`GSEventRun + 115
frame #21: 0x00234c93 UIKit`UIApplicationMain + 1160
frame #22: 0x00002c45 app`main + 181 at main.m:14

However, the audio file in soundID is created successfully, and the OSStatus error code that AudioServicesCreateSystemSoundID returns is 0.

This happens in all three iOS Simulator versions I have installed, and on my iPhone running 5.1.

This looks to be the same general backtrace as AVAudioPlayer throws breakpoint in debug mode , though mine is the result of a more direct invocation of AudioToolbox.

I want to file this with Apple, since it’s a bug in AudioToolbox (frameworks shouldn’t use exceptions for flow control, per bbum and others), but before I do, I’m wondering what other info I can gather to give them, and if there’s any way to avoid this throw (maybe by tweaking ID3 tags in this mp3?)

like image 295
cbowns Avatar asked Mar 21 '12 19:03

cbowns


2 Answers

We were running into an exception in the same place, it turned out the mp3 files it was occurring on did not have valid ID3 tags, running them through an app such as Tagr fixed them up.

like image 136
yo.ian.g Avatar answered Nov 15 '22 22:11

yo.ian.g


C++ libraries may throw and catch exceptions internally for all sorts of reasons, for example end of buffer or end of file. Whether this is an appropriate use of exceptions, good coding style or software engineering practice is debatable. As long as an exception does not make it uncaught into your code you should not worry about it.

You say that the routine returns successfully and the desired output is obtained, so nothing is wrong (i.e. it is not a bug).

like image 24
idz Avatar answered Nov 15 '22 21:11

idz