Created
May 4, 2024 08:46
-
-
Save gboyegadada/052de55d470f7b8f99f7a838f73cb6d0 to your computer and use it in GitHub Desktop.
[Swift] CGImageDestinationFinalize Error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// issue: you are writing a bunch of CGImages to disk concurrently and getting this in the logs: | |
AVEBridge Info: AVEEncoder_CreateInstance: Received CreateInstance (from VT) | |
AVEBridge Error: startUserClient: IOServiceOpen returned 0xe00002e2 | |
Assert - (err == noErr) - f: /AppleInternal/Library/BuildRoots/989643e2-e205-11ee-ae2f-ae2a9a6175d7/Library/Caches/com.apple.xbs/Sources/AppleAVEBridge/AppleAVEEncoder/AppleAVEEncoder.c l: 1955 | |
AVE FIG ERROR: createChannel failed. | |
AVEBridge Error: AVEEncoder_CreateInstance: returning err = -536870174 | |
IMKInputSession (deactivate) timed out waiting for response | |
IMKInputSession (deactivate) timed out waiting for response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fix: wrap your writing function in an actor: | |
final actor ImageWriter { | |
@discardableResult func writeCGImage(_ image: CGImage, to destinationURL: URL) -> Bool { | |
let type = UTType(filenameExtension: destinationURL.pathExtension) ?? UTType.jpeg | |
guard let destination = CGImageDestinationCreateWithURL(destinationURL as CFURL, type.identifier as CFString, 1, nil) else { return false } | |
CGImageDestinationAddImage(destination, image, nil) | |
return CGImageDestinationFinalize(destination) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment