kaddie
kaddie

Reputation: 283

EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000200 when adding filter to an image

I am trying to change an image to black and white, these images are supplied from a service call and as soon as I get the image I apply the noir filter to change them to black and white. I have been getting this dangling pointer exception only on iOS 13 the other iOS versions do not have this issue.

This is the code :

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
    }
}

Use case:

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

        })
    }
}

Stack Trace:


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


Inspecting Firebase Crashlytics, I noticed the following line in the Keys section:

CoreUI: deallocating _CUIInternalLinkRendition 205 /System/Library/CoreServices/CoreGlyphs.bundle/Assets.car

Upvotes: 1

Views: 734

Answers (1)

Jacob Relkin
Jacob Relkin

Reputation: 163308

This is likely to be a compiler or Core Image framework bug.

I would encourage you to file a bug report on Feedback Assistant.

If you look at this thread from the Apple forums, there have been issues like this before and you may just have to wait for Apple to fix it...

There are also others that have encountered your specific error message, How to fix warning "CoreUI: RunTimeThemeRefForBundleIdentifierAndName() couldn't find Assets.car in bundle with identifier: '(null)'"?

You could also try releasing a new version of the app built with the newest Xcode version and hope that the customer in question updates the app and that it solves the problem.

Upvotes: 1

Related Questions