是什么导致我的 iPad 应用程序出现 EXC_CRASH?
我从 iPad 应用程序的崩溃报告(摘录)中获得了这个符号堆栈跟踪:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
0 ImageIO 0x34528eb4 _CGImagePluginIdentifyPNG + 0
1 ImageIO 0x34528d90 _CGImageSourceBindToPlugin + 368
2 ImageIO 0x34528bda CGImageSourceGetCount + 26
3 UIKit 0x341b8f66 _UIImageRefAtPath + 366
4 UIKit 0x342650ce -[UIImage initWithContentsOfFile:] + 50
5 UIKit 0x342b0314 +[UIImage imageWithContentsOfFile:] + 28
6 DesignScene 0x00013a2a -[LTImageCache fetchImageforURL:] (LTImageCache.m:37)
…
以下是 -[LTImageCache fetchImageforURL:]
的内容:
- (UIImage *)fetchImageforURL:(NSString *)theUrl {
NSString *key = theUrl.md5Hash;
return [UIImage imageWithContentsOfFile:[self filenameForKey:key]];
}
以及 -[LTImageCache filenameForKey:] 的内容
:
- (NSString *) filenameForKey:(NSString *) key {
return [_cacheDir stringByAppendingPathComponent:key];
}
_cacheDir
ivar 创建并保留在-init
中。那么问题来了,是什么原因导致了这次事故呢?问题是:
-[LTImageCache filenameForKey:]
的返回值需要保留(它是自动释放的)- 某处未处理的异常(
+[UIImage imageWithContentsOfFile:]
声称如果图像无法识别,则返回 nil ) - 其他的东西......我无法猜测
我认为自动释放的值会很好。事实上,这段代码几个月来一直运行良好,并且这个方法在一个会话中被调用了数百次。这是在非常特殊的情况下罕见的崩溃(应用程序整夜加载,早上解锁 iPad 时崩溃)。
是什么导致了这次事故?
I got this symbolicated stack trace from a crash report from my iPad app (excerpt):
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
0 ImageIO 0x34528eb4 _CGImagePluginIdentifyPNG + 0
1 ImageIO 0x34528d90 _CGImageSourceBindToPlugin + 368
2 ImageIO 0x34528bda CGImageSourceGetCount + 26
3 UIKit 0x341b8f66 _UIImageRefAtPath + 366
4 UIKit 0x342650ce -[UIImage initWithContentsOfFile:] + 50
5 UIKit 0x342b0314 +[UIImage imageWithContentsOfFile:] + 28
6 DesignScene 0x00013a2a -[LTImageCache fetchImageforURL:] (LTImageCache.m:37)
…
Here are the contents of -[LTImageCache fetchImageforURL:]
:
- (UIImage *)fetchImageforURL:(NSString *)theUrl {
NSString *key = theUrl.md5Hash;
return [UIImage imageWithContentsOfFile:[self filenameForKey:key]];
}
And the contents of -[LTImageCache filenameForKey:]
:
- (NSString *) filenameForKey:(NSString *) key {
return [_cacheDir stringByAppendingPathComponent:key];
}
The _cacheDir
ivar is created and retained in -init
. So the question is, what caused this crash? Is the problem that:
- the return value of
-[LTImageCache filenameForKey:]
needs to be retained (it's autoreleased) - An unhandled exception somewhere (
+[UIImage imageWithContentsOfFile:]
claims to returnnil
if the image is unrecognizable) - Something else…I'm out of guesses
I would think that an autoreleased value would be fine. An in truth, this code has been working fine for months, and this method is called 100s of times in a session. This is a rare crash under very specific circumstances (the app left loaded overnight, crash upon unlocking the iPad in the morning).
What's causing this crash?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜,但它看起来像一个伪造的图像文件。这是您的应用程序包中还是您下载的?
我不认为这与内存管理有任何关系。
要测试您可以尝试使用 ImageIO 自己打开文件。
然后尝试找到图像计数。
使用
maxSize
并获取缩略图将确保您不会加载 5 兆像素的图像来放入 UI 上的 100x100 图块中。scale
是窗口的比例(对于 iPhone 4 为 2,对于其他所有设备为 1)。要查找方向,您需要使用 CGImageSourceCopyPropertiesAtIndex 函数,然后使用 kCGImagePropertyOrientation 键来获取特定图像的方向。
I'm guessing but it looks like a bogus image file. Is this in your app bundle or do you download it?
I don't think it has anything to do with memory mgt.
To test you could try using ImageIO to open the file yourself.
and then try to find the image count.
Using
maxSize
and getting a thumbnail will ensure you don't load a 5 mega-pixel image to put into a 100x100 tile on your UI.scale
is the window's scale (will be 2 for iPhone 4 and 1 for everything else).To find the orientation you need to use the
CGImageSourceCopyPropertiesAtIndex
function and then thekCGImagePropertyOrientation
key to get the orientation of the particular image.