gpt4 book ai didi

ios - 崩溃 + (UIImage *)imageWithData :(NSData *)data scale:(CGFloat)scale on iOS 8 | EXC_BAD_ACCESS UNKNOWN or KERNEL_INVALID_ADDRESS

转载 作者:可可西里 更新时间:2023-11-01 05:43:58 28 4
gpt4 key购买 nike

我的应用程序的前 2 次崩溃发生在以下方法中:

+ (UIImage *)imageWithData:(NSData *)data scale:(CGFloat)scale

到目前为止,它已经发生了 2000 多次,根据崩溃报告,它以稍微不同的方式表现出来:

EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x00000004
Thread : Crashed: com.apple.main-thread
0 ImageIO 0x27b6a1b6 CGImagePlusSetImageBlockProc + 41
1 libsystem_malloc.dylib 0x34a5139b calloc + 58
2 ImageIO 0x27b671c5 initImagePng + 4492
3 ImageIO 0x27b65a2f makeImagePlus + 930
4 ImageIO 0x27b65271 CGImageSourceCreateImageAtIndex + 160
5 UIKit 0x2a1e0bf3 _UIImageRefFromData + 262
6 UIKit 0x2a32d191 -[UIImage(UIImagePrivate) _initWithData:preserveScale:cache:] + 76
7 UIKit 0x2a1e0ae5 -[UIImage initWithData:] + 28
8 UIKit 0x2a2a36af -[UIImage initWithData:scale:] + 22
9 UIKit 0x2a32b721 +[UIImage imageWithData:scale:] + 56

EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x00000000
Thread : Crashed: com.apple.main-thread
0 CoreFoundation 0x25bca41c CFArrayGetCount + 23
1 ImageIO 0x26c3898b getImagePlus + 118
2 ImageIO 0x26c3898b getImagePlus + 118
3 ImageIO 0x26c38433 makeImagePlus + 46
4 ImageIO 0x26c37fed CGImageSourceCreateImageAtIndex + 160
5 UIKit 0x292954c3 _UIImageRefFromData + 282
6 UIKit 0x293e1ad9 -[UIImage(UIImagePrivate) _initWithData:preserveScale:cache:] + 76
7 UIKit 0x292953a5 -[UIImage initWithData:] + 28
8 UIKit 0x29357ee7 -[UIImage initWithData:scale:] + 22
9 UIKit 0x293e0081 +[UIImage imageWithData:scale:] + 56

EXC_BAD_ACCESS UNKNOWN at 0x0000000104f44000
Thread : Crashed: com.apple.main-thread
0 libsystem_platform.dylib 0x0000000194795390 _platform_memmove + 320
1 libsystem_c.dylib 0x0000000194690424 __memcpy_chk + 32
2 libsystem_c.dylib 0x0000000194690424 __memcpy_chk + 32
3 ImageIO 0x0000000184a3172c _CGImageSourceBindToPlugin + 316
4 ImageIO 0x0000000184a31574 CGImageSourceGetCount + 112
5 UIKit 0x000000018816d46c _UIImageRefFromData + 276
6 UIKit 0x00000001882d1c20 -[UIImage(UIImagePrivate) _initWithData:preserveScale:cache:] + 112
7 UIKit 0x000000018823e21c -[UIImage initWithData:scale:] + 32
8 UIKit 0x00000001882cffa4 +[UIImage imageWithData:scale:] + 72

我看不出我的代码会如何影响这个,但我尝试将 nil 发送到此方法,但它只返回 nil。损坏的 NSData 会导致这次崩溃吗?此方法是否保留 NSData?会不会是因为在处理这条线时释放了 NSData?我不这么认为,因为它是同步的,对吗?

除此之外,我无法重现此错误,但由于我们拥有庞大的用户群,它经常发生。我还注意到它发生在 iOS 8 上的次数为 99%。

任何帮助将不胜感激。

最佳答案

您使用的库是 AFNetwork 还是 Hanekee?由于 ios8 UIImage imageWithData,我刚刚向这两个库提交了拉取请求。似乎带有数据的 UIImage 不是线程安全的,这意味着从不同线程同时调用它会崩溃....复制它的一种方法是测试以下代码:

let data = NSData(contentsOfURL: NSURL(string: "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTf4P0V2TrszykwPguyeulcSt4vwQPcvvWKKq_RePhUUVFoHevG9lw8GVcw")!)
var test: Array<UIImage> = []
let lock = NSLock()
for i in 0...10000 {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { () -> Void in
NSLog("Processing \(i)")
let a = UIImage(data:data!)
NSLog("Processed \(i)")
lock.lock()
test.append(a!)
test.removeLast()
lock.unlock()
})

因此请确保同步 UIImage(data:data!) 或 [UIImage imageWithData:data] 调用以避免同时调用。

拉取请求:

哈内克:https://github.com/Haneke/HanekeSwift/pull/207

AF 网络:https://github.com/AFNetworking/AFNetworking/pull/2815

关于ios - 崩溃 + (UIImage *)imageWithData :(NSData *)data scale:(CGFloat)scale on iOS 8 | EXC_BAD_ACCESS UNKNOWN or KERNEL_INVALID_ADDRESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28905925/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com