Error creating texture from camera capture on macOS, working fine on iOS

I'm using the exact same code to capture frames from video and render then through Metal, but while it works when I run on my iOS devices, when I run the code on my Mac I get a cryptic error.


CVMetalTextureCacheCreateTextureFromImage is returning kCVReturnError. Is there a way to get a better error description? Usually Apple error messages are pretty good.

Answered by JohnCoates in 183830022

I tried posting a link to the full project & relevant source files, but it's currently waiting for moderation.


After reading though the headers again, I did miss somehting.

I set the pixel format on the AVCaptureVideoDataOutput object, but neglected to set kCVPixelBufferMetalCompatibilityKey to true.

With kCVPixelBufferMetalCompatibilityKey set to true in the object's videoSettings, it's now grabbing the texture correctly.

I've put up a project showing this problem on GitHub.

It has a macOS target & an iOS target. The relevant part of the code is here: https://github.com/JohnCoatesOSS/MetalSandbox/blob/master/MetalSandbox/Renderer.swift#L187


The full project is here: https://github.com/JohnCoatesOSS/MetalSandbox

Unfortunately, I don't think there is a way to get more information related to this error. Can you share any more details of how you're invoking this function?

Accepted Answer

I tried posting a link to the full project & relevant source files, but it's currently waiting for moderation.


After reading though the headers again, I did miss somehting.

I set the pixel format on the AVCaptureVideoDataOutput object, but neglected to set kCVPixelBufferMetalCompatibilityKey to true.

With kCVPixelBufferMetalCompatibilityKey set to true in the object's videoSettings, it's now grabbing the texture correctly.

Error creating texture from camera capture on macOS, working fine on iOS
 
 
Q