0

I'm trying to save some photos after capture. But while saving CGImageDestinationFinalize fails & mostly crashes.

let cgImage: CGImage...

let data: CFMutableData = CFDataCreateMutable(nil, 0)
// Older phones can't save to HEIC, so falling back to JPEG.
let destination
            = CGImageDestinationCreateWithData(data, "public.heic" as CFString, 1, nil)
              ?? CGImageDestinationCreateWithData(data, kUTTypeJPEG as CFString, 1, nil)!

CGImageDestinationAddImage(destination, cgImage, metadata)
NSLog(log: "Check #1") // This line executes
let _ = CGImageDestinationFinalize(destination) // Crashes here (fails/ returns false)
NSLog(log: "Check #2") // not executed
PHPhotoLibrary.save(photo: data as Data, success: success)

It crashes with:

Message from debugger: Terminated due to memory issue

I tested it on iPhone7+ & iPhoneXS, it's working. But crashing on my iPhoneX. All of them running iOS12.2. While this answer says it was a known issue in iOS 9 that has been resolved in iOS 10.

It does not tell the reason or give me a stack trace. Any ideas what might be wrong?

Ajo
  • 337
  • 4
  • 12

0 Answers0