EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000200 向图像添加过滤器时
Posted
技术标签:
【中文标题】EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000200 向图像添加过滤器时【英文标题】:EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000200 when adding filter to an image 【发布时间】:2020-02-24 06:20:53 【问题描述】:我正在尝试将图像更改为黑白,这些图像是通过服务调用提供的,一旦我获得图像,我就会应用黑色滤镜将它们更改为黑白。我只在 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:取消分配 _CUIInternalLinkRendition 205 /System/Library/CoreServices/CoreGlyphs.bundle/Assets.car
【问题讨论】:
您正在强制解开对noir
属性的调用。您是否尝试在 return nil
分支中设置断点?
我似乎无法在我的物理设备上重现该错误,但是如果崩溃是由于强制打开可选选项而导致的,那不是Fatal error: Unexpectedly found nil while unwrapping an Optional value
是的。那么,这是只在野外遇到的崩溃吗?嗯...
是的,仅在 iOS 13 上
您知道崩溃发生在什么设备上吗?我觉得 Core Image 决定创建一个基于 OpenGL 的上下文(而不是基于 Metal)很奇怪。这应该只发生在非常旧的设备上(不支持 iOS 13)...
【参考方案1】:
这很可能是编译器或 Core Image 框架的错误。
我鼓励您在 Feedback Assistant 上提交错误报告。
如果你在 Apple 论坛上查看 this thread,之前也有过类似的问题,你可能只需要等待 Apple 修复它......
还有其他人遇到了你的具体错误信息,How to fix warning "CoreUI: RunTimeThemeRefForBundleIdentifierAndName() couldn't find Assets.car in bundle with identifier: '(null)'"?
您也可以尝试发布使用最新 Xcode 版本构建的应用程序的新版本,并希望相关客户更新应用程序并解决问题。
【讨论】:
以上是关于EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000200 向图像添加过滤器时的主要内容,如果未能解决你的问题,请参考以下文章
setCollectionViewLayout 上的 EXC_BAD_ACCESS