我遇到了一个奇怪的崩溃,表现为一个 EXC_BAD_ACCESS,它总是发生在 FMOD 打开的线程调用堆栈上的某个地方,调用它是 OpenCallback(当 FMOD 在内存中找不到声音时调用的函数,所以需要加载它从磁盘)。崩溃发生在许多不同的地方,我似乎找不到任何改变的原因,因为执行路径基本上是相同的。我注意到的一件事是,在调用堆栈中有两个对同一个非递归构造函数的调用彼此相邻。也就是说,调试器(Xcode/LLDB,但我已经用 Xcode/GDB 尝试过)认为这个构造函数正在调用自己,但事实并非如此。
我注意到的另一件事是这些调用的偏移量是不同的,即使它们指的是同一个函数。有谁知道可能会发生什么?我很困惑,因为我什至不知道这种问题叫什么(因此不能谷歌它)。
这是其中一次崩溃的调用堆栈(有些东西为了匿名而被重命名,但我试图保持命名约定一致)。请注意,CString 和 PIFilePath 构造函数分别被调用两次,并且是相邻的。
* thread #49: tid = 0x6003, 0x009d3220 MyProject`SpinLock::Lock() + 64 at spinlock.h:73, stop reason = EXC_BAD_ACCESS (code=2, address=0xb01f7ffc)
frame #0: 0x009d3220 MyProject`SpinLock::Lock() + 64 at spinlock.h:73
frame #1: 0x0099d8e0 MyProject`tcmalloc::CentralFreeList::RemoveRange(void**, void**, int) + 160 at central_freelist.cc:211
frame #2: 0x009b4989 MyProject`tcmalloc::ThreadCache::FetchFromCentralCache(unsigned long, unsigned long) + 281 at thread_cache.cc:149
frame #3: 0x009d66fc MyProject`tcmalloc::ThreadCache::Allocate(unsigned long, unsigned long) + 332 at thread_cache.h:330
frame #4: 0x009ce123 MyProject`do_malloc + 227 at tcmalloc.cc:960
frame #5: 0x009ce1e5 MyProject`do_malloc_or_cpp_alloc + 85 at tcmalloc.cc:897
frame #6: 0x009d1285 MyProject`MallocBlock::Allocate(unsigned long, int) + 517 at debugallocation.cc:534
frame #7: 0x009ce460 MyProject`DebugAllocate + 48 at debugallocation.cc:968
frame #8: 0x011cc942 MyProject`malloc + 50
frame #9: 0x00a80bbf MyProject`CSystemUtilities::CSAllocate(long, unsigned long, void*) + 47 at CSystemUtilities.cpp:2358
frame #10: 0x96a08d17 CoreFoundation`CFAllocatorAllocate + 343
frame #11: 0x96a0de4b CoreFoundation`__CFStringChangeSizeMultiple + 1179
frame #12: 0x96a219d6 CoreFoundation`CFStringCreateMutableCopy + 454
frame #13: 0x00a9bae2 MyProject`CString::SetCFString(__CFString const*, bool) + 114 at CString.cpp:527
frame #14: 0x00a9bcb0 MyProject`CString::CString(CString const&) + 112 at CString.cpp:189
frame #15: 0x00a9bc1f MyProject`CString::CString(CString const&) + 47 at CString.cpp:190
frame #16: 0x00aa3a9e MyProject`PIFilePath::NormalisePath(CString const&, long, bool, unsigned short) + 2142 at PIFilePath.cpp:2021
frame #17: 0x00aa2dc9 MyProject`PIFilePath::FindPathInList(CString const&, std::vector<CString, std::allocator<CString> > const&) + 89 at PIFilePath.cpp:1716
frame #18: 0x00aa3d26 MyProject`PIFilePath::IsAbsolutePath(CString const&) + 134 at PIFilePath.cpp:465
frame #19: 0x00aa62d1 MyProject`PIFilePath::ApplyMappingsToPath(CString const&, CString const&, bool) + 1041 at PIFilePath.cpp:1323
frame #20: 0x00aa292d MyProject`PIFilePath::TranslatePath(CString const&) const + 4157 at PIFilePath.cpp:1645
frame #21: 0x00aa15ad MyProject`PIFilePath::SetPath(CString const&, PIFilePath::ConvertPathMode) + 253 at PIFilePath.cpp:175
frame #22: 0x00aa1460 MyProject`PIFilePath::PIFilePath(CString const&, PIFilePath::ConvertPathMode) + 96 at PIFilePath.cpp:122
frame #23: 0x00aa13dd MyProject`PIFilePath::PIFilePath(CString const&, PIFilePath::ConvertPathMode) + 61 at PIFilePath.cpp:123
frame #24: 0x00becad8 MyProject`FileAttributes + 88 at pi_files.cpp:3341
frame #25: 0x0090702b MyProject`SystemStuff::CWinFS::Exists(char const*) + 219 at fsWin.cpp:627
frame #26: 0x008e2892 MyProject`SystemStuff::CMultiFS::FindFS(char const*) + 162 at fsMulti.cpp:390
frame #27: 0x008e1466 MyProject`SystemStuff::CMultiFS::Open(SystemStuff::RCPtr<SystemStuff::IBlock>&, char const*, unsigned long) + 134 at fsMulti.cpp:223
frame #28: 0x008db911 MyProject`SystemStuff::CDispatchFS::Open(SystemStuff::RCPtr<SystemStuff::IBlock>&, char const*, unsigned long) + 321 at fsDispatch.cpp:158
frame #29: 0x008cbb89 MyProject`SystemStuff::FS::Open(SystemStuff::RCPtr<SystemStuff::IBlock>&, char const*, unsigned long) + 233 at fs.cpp:135
frame #30: 0x00985611 MyProject`OpenCallback(char const*, int, unsigned int*, void**, void**) + 177 at sndFMODEx.cpp:324
frame #31: 0x029ecf59 libfmodex.dylib`FMOD::DSP::disconnectFrom(FMOD::DSP*) + 25999
frame #32: 0x029ee7cb libfmodex.dylib`FMOD_File_SetDiskBusy + 4861
frame #33: 0x02a0c15b libfmodex.dylib`FMOD::SystemI::createSoundInternal(char const*, unsigned int, unsigned int, unsigned int, FMOD_CREATESOUNDEXINFO*, FMOD::File**, bool, FMOD::SoundI**) + 2413
frame #34: 0x0298b6aa libfmodex.dylib
frame #35: 0x02a11d2c libfmodex.dylib`FMOD::SystemI::createSoundInternal(char const*, unsigned int, unsigned int, unsigned int, FMOD_CREATESOUNDEXINFO*, FMOD::File**, bool, FMOD::SoundI**) + 25918
frame #36: 0x91b6d557 libsystem_c.dylib`_pthread_start + 344
这是我大约 40% 的时间发生的崩溃,另外 60% 的时间它失败了NormalisePath
(但上面的调用堆栈是相同的)。