iOS应用程序启动时出现奇怪的崩溃

5

我的项目名叫OBI,在Xcode中启动时运行良好,但是当我创建.ipa文件后,它会崩溃并提供日志。在项目中没有名为Mutex、DelayedPointerDeletionManager或MemoryManager的类,因此我无法理解这个异常出现的原因。

Thread 0 Crashed:
0   libsystem_pthread.dylib         0x396b7046 _pthread_mutex_check_init + 14
1   libsystem_pthread.dylib         0x396b6e32 _pthread_mutex_lock + 22
2   OBI                             0x02a74f20 Mutex::Lock() (Mutex.cpp:152)
3   OBI                             0x02838930 DelayedPointerDeletionManager::AddPointerToMainThreadDealloc(void*, MemLabelId) (Mutex.h:32)
4   OBI                             0x028384a4 MemoryManager::Deallocate(void*, MemLabelId) (MemoryManager.cpp:1082)
5   OBI                             0x028384e4 operator delete[](void*) (MemoryManager.cpp:114)
6   OBI                             0x01d28010 std::locale::locale<boost::filesystem::detail::utf8_codecvt_facet>(std::locale const&, boost::filesystem::detail::utf8_codecvt_facet*) (locale_classes.h:581)
7   OBI                             0x01d281c4 ___lldb_unnamed_function148423$$OBI + 232
8   dyld                            0x2be5b59e ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 174
9   dyld                            0x2be5b6ac ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 16
10  dyld                            0x2be58d34 ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&) + 356
11  dyld                            0x2be58b88 ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 36
12  dyld                            0x2be4fd38 dyld::initializeMainExecutable() + 164
13  dyld                            0x2be52ab4 dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 1748
14  dyld                            0x2be4f22a dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) + 346
15  dyld                            0x2be4f064 _dyld_start + 60

编辑,从控制台中选取几行。

Oct 16 14:43:18 Sergiys-iPad kernel[0] <Debug>: launchd[9526] Container: /private/var/mobile/Applications/AA46736B-6348-42BA-A8F0-DD63DC535AF6 (sandbox)
Oct 16 14:43:19 Sergiys-iPad ReportCrash[9527] <Notice>: ReportCrash acting against PID 9526
Oct 16 14:43:19 Sergiys-iPad ReportCrash[9527] <Notice>: Formulating crash report for process OBI[9526]
Oct 16 14:43:19 Sergiys-iPad com.apple.launchd[1] (UIKitApplication:com.mycompany.OBIQA[0x14dc][9526]) <Warning>: (UIKitApplication:com.mycompany.OBIQA[0x14dc]) Job appears to have crashed: Segmentation fault: 11
Oct 16 14:43:19 Sergiys-iPad com.apple.launchd[1] (UIKitApplication:com.mycompany.OBIQA[0x14dc]) <Notice>: (UIKitApplication:com.mycompany.OBIQA[0x14dc]) Throttling respawn: Will start in 2147483647 seconds
Oct 16 14:43:19 Sergiys-iPad backboardd[28] <Warning>: Application 'UIKitApplication:com.mycompany.OBIQA[0x14dc]' exited abnormally with signal 11: Segmentation fault: 11
Oct 16 14:43:19 Sergiys-iPad SpringBoard[33] <Warning>: Application 'com.mycompany.OBIQA' has failed to launch too many times. Not relaunching.
Oct 16 14:43:19 Sergiys-iPad ReportCrash[9527] <Notice>: Saved crashreport to /var/mobile/Library/Logs/CrashReporter/OBI_2013-10-16-144319_Sergiys-iPad.plist using uid: 0 gid: 0, synthetic_euid: 501 egid: 0

我很乐意提供任何帮助或指导。

编辑
最终我找到了造成这个异常的原因。是在构建设置中的符号去除选项,在我将其从所有符号更改为调试符号后,一切变得正常。

1
你在applicationDidFinishLaunching中加载图片了吗?应用程序可能会超时,因为你启动时间太长了。 - wattson12
请查看此处链接:https://developer.apple.com/library/ios/qa/qa1592/_index.html - wattson12
谢谢您的评论,我会检查这个猜测,但是没有任何超时警告之类的。您能解释一下您从哪里得到这个信息吗? - sage444
添加了一个带有更多解释的答案。 - wattson12
3个回答

4

这是因为iOS将您的类加载到内存中时,在动态加载器中崩溃。 这个过程的一部分是调用实现该方法的任何类的+load。

可能的原因之一是在+load中做了太多的工作,并且被“无法按时启动”杀死。 提供完整的崩溃日志将显示是否是这种情况。


0

ImageLoader与代码片段(外部框架、库)的加载相关联。您应确保所有这些都可以被二进制文件“看到”。在XCode中构建可以将所有内容放在同一个文件夹中,因此您不会遇到路径问题,但是,特别是如果您正在引用第三方框架,则需要确保它们可以被主可执行文件“看到”。控制台是否有任何输出?


谢谢您的回复,我添加了控制台输出。 请问您能否解释一下如何检查库是否“可见”,因为有很多第三方框架和库。 - sage444

0
从我所看到的情况(如果你展示一些代码,特别是你的applicationDidFinishLaunching方法,会更有帮助),似乎你的应用程序启动时间太长,被操作系统杀死。
应用程序有一定的时间限制来设置根视图控制器和进行任何基本设置。如果时间太长,操作系统将认为它不响应并将其终止。当使用调试器附加运行时,你不会注意到此问题,因为在此情况下时间限制已禁用:参见这里 https://developer.apple.com/library/ios/qa/qa1592/_index.html 如果你正在应用委托中下载图片,我建议切换到异步方法,并且可能要从使用该图片的视图控制器中处理图像加载。
编辑:看起来你从控制台获得了一个与问答描述不同的错误,但没有任何代码,我无法提供更多帮助。

感谢您的帮助。我无法提供代码,但我只是在“applicationDidFinishLaunching”方法中注释了所有内容(仅保留return YES),然后像往常一样进行了归档。应用程序仍然会因为相同的异常而崩溃。 - sage444
好的,那可能不是问题所在。没有代码我帮不了太多忙,但我会查看ImageLoader类。 - wattson12
看起来你误解了 ImageLoader,这不是我的类,我认为它是系统图像加载器,用于加载应用程序图片,而不是图形图片。 - sage444
是的,看起来你是对的,那我很抱歉,我对那个类不是很了解。 - wattson12
这个回答所说的与问题中显示的内容毫无关系。它为什么会有任何赞成票对我来说是个谜。 - Léo Natan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接