我正在尝试将图像更改为黑白,这些图像是从服务调用中提供的,一旦获得图像,我就会应用黑色滤镜将它们更改为黑白。我只在 iOS 13 上遇到过这个悬空指针异常,其他 iOS 版本没有这个问题。
这是代码:
extension UIImage {
var noir: UIImage? {
let context = CIContext(options: nil)
guard let currentFilter = CIFilter(name: "CIPhotoEffectNoir") else {
return nil
}
currentFilter.setValue(CIImage(image: self), forKey: kCIInputImageKey)
if let output = currentFilter.outputImage,
let cgImage = context.createCGImage(output, from: output.extent) {
return UIImage(cgImage: cgImage, scale: scale, orientation: imageOrientation)
}
return nil
}
}
用例:
var member: Faculty? {
didSet {
guard let lecturer = self.member else {
return
}
FacultyService.image(
atPath: lecturer.thumbnailPath,
process: { (image: UIImage) -> UIImage in
if lecturer.Id != nil {
return image.noir!.withRenderingMode(.alwaysOriginal)
} else {
return image.withRenderingMode(.alwaysOriginal)
}
},
success: { [weak self] (path: String, image: UIImage) -> Void in
guard let strongSelf = self else { return }
if path == strongSelf.member?.imagePath {
self.imageButton.setImage(image, for: .normal)
self.imageButton.layer.animate()
}
},
failure: { () -> Void in
})
}
}
堆栈跟踪:
Crashed: com.imas.MNT.HTTPSessionSharedCompletionQueue
0 CoreImage 0x19e748aa4 CI::GLContext::init() + 88
1 CoreImage 0x19e748a80 CI::GLContext::init() + 52
2 CoreImage 0x19e748df0 CI::GLContext::GLContext(CI::GLContext::ShareContextInfo, CGColorSpace*, CGColorSpace*, CI::PixelFormat, bool, unsigned long, bool, bool) + 416
3 CoreImage 0x19e748e2c CI::GLContext::GLContext(CI::GLContext::ShareContextInfo, CGColorSpace*, CGColorSpace*, CI::PixelFormat, bool, unsigned long, bool, bool) + 24
4 CoreImage 0x19e5cc988 +[CIContext(Internal) internalContextWithEAGLContext:options:] + 716
5 CoreImage 0x19e5c9d88 -[CIContext initWithOptions:] + 484
6 GetHornet-AppStore 0x1049bf5f8 UIImage.noir.getter + 4330436088 (<compiler-generated>:4330436088)
7 GetHornet-AppStore 0x104d2d2b8 closure #2 in FacultyMemberCell.member.didset + 75 (FacultyMemberCell.swift:75)
8 GetHornet-AppStore 0x104ad7e24 thunk for @escaping @callee_guaranteed (@guaranteed UIImage) -> (@owned UIImage) + 4331585060 (<compiler-generated>:4331585060)
9 GetHornet-AppStore 0x104954a94 __80-[FacultyService imageAtPath:progress:process:success:failure:]_block_invoke + 125 (FacultyService.m:125)
10 AFNetworking 0x105cb4900 __116-[AFHTTPSessionManager dataTaskWithHTTPMethod:URLString:parameters:uploadProgress:downloadProgress:success:failure:]_block_invoke_2 + 301 (AFHTTPSessionManager.m:301)
11 AFNetworking 0x105cc6640 __72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_2.102 + 248 (AFURLSessionManager.m:248)
12 libdispatch.dylib 0x19ca3e610 _dispatch_call_block_and_release + 24
13 libdispatch.dylib 0x19ca3f184 _dispatch_client_callout + 16
14 libdispatch.dylib 0x19ca1c85c _dispatch_lane_serial_drain$VARIANT$armv81 + 896
15 libdispatch.dylib 0x19ca1d128 _dispatch_lane_invoke$VARIANT$armv81 + 400
16 libdispatch.dylib 0x19ca2643c _dispatch_workloop_worker_thread + 576
17 libsystem_pthread.dylib 0x19ca8eb88 _pthread_wqthread + 276
18 libsystem_pthread.dylib 0x19ca91760 start_wqthread + 8
检查 Firebase Crashlytics,我注意到 Keys 部分中的以下行:
CoreUI: deallocating _CUIInternalLinkRendition 205 /System/Library/CoreServices/CoreGlyphs.bundle/Assets.car
最佳答案
这很可能是编译器或 Core Image 框架的错误。
我鼓励您在 Feedback Assistant 上提交错误报告.
如果你看this thread从 Apple 论坛中,以前有过类似的问题,您可能只需要等待 Apple 解决它...
还有其他人遇到了您的特定错误消息,How to fix warning "CoreUI: RunTimeThemeRefForBundleIdentifierAndName() couldn't find Assets.car in bundle with identifier: '(null)'"?
您还可以尝试发布使用最新 Xcode 版本构建的应用程序的新版本,并希望相关客户更新应用程序并解决问题。
关于ios - EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000200 向图像添加过滤器时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60370510/