Occasionally my Cocoa app crashes while trying to load a system sound. I've not been able to reproduce this myself, but a few users have sent me crash reports.
The stack trace is always the same (see below). The app opens a modal dialog, the user clicks OK, the sound is loaded and crashes:
[NSSound soundNamed:@"Hero"];
There are a few mentions of this issue on the web[1], but no resolutions. Please note that I'm loading the sound from the main thread and am not attempting to play it back. It crashes right away. Also, the sound file itself is not corrupted (I had one user email it to me and it matches the one I have installed).
Crash log excerpt:
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000009a0d204
VM Regions Near 0x9a0d204:
shared memory 0000000009310000-0000000009511000 [ 2052K] r--/r-- SM=SHM
--> MALLOC_TINY 0000000009a00000-0000000009c00000 [ 2048K] rw-/rwx SM=COW
MALLOC_LARGE 0000000009c00000-000000000bc9c000 [ 32.6M] rw-/rwx SM=PRV
Application Specific Information:
objc[8625]: garbage collection is OFF
Performing @selector(ok:) from sender NSButton 0x236510
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 ??? 0x09a0d204 0 + 161534468
1 com.apple.audio.units.Components 0x7000ed9d AUHAL::AUHAL(ComponentInstanceRecord*, unsigned long, bool) + 775
2 com.apple.audio.units.Components 0x7002feff ComponentEntryPoint<DefaultOutputAU>::Dispatch(ComponentParameters*, DefaultOutputAU*) + 144
3 com.apple.CoreServices.CarbonCore 0x98487949 CallComponent + 223
4 com.apple.CoreServices.CarbonCore 0x98487992 CallComponentDispatch + 29
5 com.apple.CoreServices.CarbonCore 0x984f3b6c CallComponentOpen + 43
6 com.apple.CoreServices.CarbonCore 0x98486608 OpenAComponent + 426
7 com.apple.CoreServices.CarbonCore 0x98486688 OpenComponent + 24
8 com.apple.AppKit 0x9b810cd3 _initializeCA + 1115
9 com.apple.AppKit 0x9b811c23 -[NSSound _postInitialization] + 349
10 com.apple.AppKit 0x9b810609 -[NSSound initWithContentsOfURL:byReference:] + 263
11 com.apple.AppKit 开发者_JS百科 0x9b812767 +[NSSound _searchForSoundNamed:] + 1044
12 com.apple.AppKit 0x9b8122de +[NSSound soundNamed:] + 227
1: http://lists.apple.com/archives/Cocoa-dev/2007/Oct/msg01159.html
The resolutions (or rather workarounds) of the problem you mentionned were applied in Transmission changeset 3540: don't allow custom sounds and later in changeset 5577: supporting custom user sounds on Leopard.
Unfortunately, the backtraces don't match and your crash log is from Snow Leopard or Lion so these solutions probably don't apply for you. I would suggest you to file a bug report to Apple.
精彩评论