偶爾我的Cocoa應用程序在嘗試加載系統聲音時崩潰。我一直無法自己重現這一點,但一些用戶向我發送了崩潰報告。嘗試加載系統聲音時NSSound崩潰
堆棧跟蹤總是相同的(見下文)。該應用程序會打開一個模態對話框,用戶點擊OK,加載聲音和崩潰:
[NSSound soundNamed:@"Hero"];
有網[1],但沒有決議,在這個問題上的幾個提及。請注意,我正在從主線程加載聲音,而不是試圖播放它。它馬上崩潰。此外,聲音文件本身沒有損壞(我有一個用戶通過電子郵件發送給我,它與我安裝的相匹配)。
崩潰日誌摘錄:
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 0x9b812767 +[NSSound _searchForSoundNamed:] + 1044
12 com.apple.AppKit 0x9b8122de +[NSSound soundNamed:] + 227
1:http://lists.apple.com/archives/Cocoa-dev/2007/Oct/msg01159.html
向我們展示更多代碼。你在哪裏使用這種聲音?... – Nekto
顯示更多的代碼不會幫助,回溯很清楚:'+ [NSSound soundNamed:]'在某些情況下導致崩潰。 – 0xced