vImageBuffer_InitWithCGImage fails with Xcode 26 but succeeds with Xcode 15I am

I am attempting to load a jpeg image into a vImage_Buffer.

I am just trying to get the data in an ARGB format. This code works fine in the Xcode 15 build , but fails with kvImageInvalidParameter error from vImageBuffer_InitWithCGImage in the Xcode 26 build.

This code is written in ObjectiveC++. Here is a code fragment:

int CDib_ARGB::Load(LPCSTR pFilename) { int rc = 0; if (NULL == m_pRaw_vImage_Buffer) { NSString *pNS_filename = [[NSString alloc]initWithUTF8String:pFilename]; NSImage *pNSImage = [[NSImage alloc] initWithContentsOfFile:pNS_filename]; if (nil == pNSImage) rc = -1; else { int width = pNSImage.size.width; int height = pNSImage.size.height; if (pNSImage.representations) { NSImageRep *imageRep; int jj; width = 0; height = 0; for (jj = 0; jj < pNSImage.representations.count; jj++) { imageRep = pNSImage.representations[jj]; if (imageRep.pixelsWide > width) width = imageRep.pixelsWide; if (imageRep.pixelsHigh > height) height = imageRep.pixelsHigh; } } NSSize imageSize = NSMakeSize(width, height); NSRect imageRect = NSMakeRect(0, 0, width, height); pNSImage.size = imageSize; CGImageRef cgImage = [pNSImage CGImageForProposedRect:&imageRect context:NULL hints:nil]; if (nil == cgImage) rc = -1; else { //Alloc and load vImage_Buffer. vImage_Buffer *pvImage_Buffer = new vImage_Buffer; if (NULL == pvImage_Buffer) rc = -1; else { vImage_CGImageFormat format; format.bitsPerComponent = 8; format.bitsPerPixel = 32; format.colorSpace = nil; format.bitmapInfo = kCGImageAlphaFirst | kCGBitmapByteOrderDefault;//ARGB8888 format.version = 0; format.decode = nil; format.renderingIntent = kCGRenderingIntentDefault;

                memset(pvImage_Buffer, 0, sizeof(vImage_Buffer));

                long status = vImageBuffer_InitWithCGImage(pvImage_Buffer, &format, nil, cgImage, kvImagePrintDiagnosticsToConsole);
                if (kvImageNoError != status)
                { //This is where Xcode 26 sends me.
                    delete pvImage_Buffer;
                    rc = -1;
                }

=========================

Thank you for your post. While I do not have an answer for you, I would recommend formatting the code in a way that is easily copyable and readable, such as using code block formatting like, but make sure to provide character returns as well, if you copy from Xcode will look way nicer.

nt CDib_ARGB::Load(LPCSTR pFilename) { int rc = 0; if (NULL == m_pRaw_vImage_Buffer) { NSString *pNS_filename = [[NSString alloc]initWithUTF8String:pFilename]; NSImage *pNSImage = [[NSImage alloc] initWithContentsOfFile:pNS_filename]; if (nil == pNSImage) rc = -1; else { int width = pNSImage.size.width; int height = pNSImage.size.height; if (pNSImage.representations) { NSImageRep *imageRep; int jj; width = 0; height = 0; for (jj = 0; jj < pNSImage.representations.count; jj++) { imageRep = pNSImage.representations[jj]; if (imageRep.pixelsWide > width) width = imageRep.pixelsWide; if (imageRep.pixelsHigh > height) height = imageRep.pixelsHigh; } } NSSize imageSize = NSMakeSize(width, height); NSRect imageRect = NSMakeRect(0, 0, width, height); pNSImage.size = imageSize; CGImageRef cgImage = [pNSImage CGImageForProposedRect:&imageRect context:NULL hints:nil]; if (nil == cgImage) rc = -1; else { //Alloc and load vImage_Buffer. vImage_Buffer *pvImage_Buffer = new vImage_Buffer; if (NULL == pvImage_Buffer) rc = -1; else { vImage_CGImageFormat format; format.bitsPerComponent = 8; format.bitsPerPixel = 32; format.colorSpace = nil; format.bitmapInfo = kCGImageAlphaFirst | kCGBitmapByteOrderDefault;//ARGB8888 format.version = 0; format.decode = nil; format.renderingIntent = kCGRenderingIntentDefault;

It will be beneficial for readers of your post if an expert here provides suggestions or the desired answer.

Albert Pascual
  Worldwide Developer Relations.

Second attempt to paste code: int CDib_ARGB::Load(LPCSTR pFilename) { int rc = 0; if (NULL == m_pRaw_vImage_Buffer) { NSString *pNS_filename = [[NSString alloc]initWithUTF8String:pFilename]; NSImage *pNSImage = [[NSImage alloc] initWithContentsOfFile:pNS_filename]; if (nil == pNSImage) rc = -1; else { int width = pNSImage.size.width; int height = pNSImage.size.height; if (pNSImage.representations) { NSImageRep *imageRep; int jj; width = 0; height = 0; for (jj = 0; jj < pNSImage.representations.count; jj++) { imageRep = pNSImage.representations[jj]; if (imageRep.pixelsWide > width) width = imageRep.pixelsWide; if (imageRep.pixelsHigh > height) height = imageRep.pixelsHigh; } } NSSize imageSize = NSMakeSize(width, height); NSRect imageRect = NSMakeRect(0, 0, width, height); pNSImage.size = imageSize; CGImageRef cgImage = [pNSImage CGImageForProposedRect:&imageRect context:NULL hints:nil]; if (nil == cgImage) rc = -1;

I am trying to paste from Xcode without much success. The dev forum tool is pretty awful. Is should not really matter though. The vImageBuffer_InitWithCGImage() call is pretty clear. I will try to attach a file with the code fragment. I note that the add file option does not let me add a file with a .mm extension. I will change it to .txt and see what happens.

The vImageBuffer_InitWithCGImage() call is pretty clear. I will try to attach a file with the code fragment. I note that the add file option does not let me add a file with a .mm extension. I will change it to .txt and see what happens.

This the image file that causes the problem.

Thank you for providing some code. I am investigating the problem you reported and I’ll respond with some analysis shortly.

Hello. I tested using Xcode Version 26.2 (17C52) on macOS 26.2 (25C56) using your code with the following color format files and I was unable to reproduce a crash. Can you provide a copy of the image file you are using for testing?

Formats I tried:

RGB_NoneSkipFirst_8bit 8 bits/component, 32 bits/pixel RGBX format (no alpha, skip first byte) sRGB color space AlphaInfo: kCGImageAlphaNoneSkipFirst

RGB_NoneSkipLast_8bit 8 bits/component, 32 bits/pixel XRGB format (no alpha, skip last byte) sRGB color space AlphaInfo: kCGImageAlphaNoneSkipLast

RGB_AlphaPremultFirst_8bit 8 bits/component, 32 bits/pixel ARGB format with premultiplied alpha sRGB color space AlphaInfo: kCGImageAlphaPremultipliedFirst

RGB_AlphaPremultLast_8bit 8 bits/component, 32 bits/pixel RGBA format with premultiplied alpha sRGB color space AlphaInfo: kCGImageAlphaPremultipliedLast

RGB_AlphaPremultLast_16bit 16 bits/component, 64 bits/pixel RGBA format with premultiplied alpha sRGB color space AlphaInfo: kCGImageAlphaPremultipliedLast

RGB_AlphaPremultLast_32bit_Float (saved as 16 bit by PNG) 16 bits/component, 64 bits/pixel RGBA format with premultiplied alpha sRGB color space AlphaInfo: kCGImageAlphaPremultipliedLast

Gray_NoAlpha_8bit 8 bits/component, 8 bits/pixel Grayscale format, no alpha Generic Gray Gamma 2.2 color space AlphaInfo: kCGImageAlphaNone

RGB_NoAlpha_8bit 8 bits/component, 32 bits/pixel RGBX format ICC based "Warm" RGB color space AlphaInfo: kCGImageAlphaNoneSkipLast

Thank you for doing some testing. That is great.

I am a little confused though. I uploaded the image file earlier on the thread. I have reuploaded for this reply. Its name is PXL_20251217_201630453.MP.jpeg .

Note also that the sample code contained the line: format.bitmapInfo = kCGImageAlphaFirst | kCGBitmapByteOrderDefault;//ARGB8888

That is slightly different than what you tried. Note also that my code did not crash.

vImageBuffer_InitWithCGImage returned with the error code kvImageInvalidParameter.

A complete project to reproduce the error has been uploaded as a zip archive via Feedback Assistant. Feedback Assistant designates the report as FB21893783 . The jpeg file is also in the zip archive.

Xcode debug console:

-[MoeDocController openDocumentWithContentsOfURL:display:completionHandler:] file:///Users/elliotleonard/test/PXL_20251217_201630453.MP.jpeg fence tx observer 1f8eb timed out after 0.600000 <<<< CMPhotoJFIFUtilities >>>> signalled err=-17102 at <>:1776 <<<< CMPhotoJFIFUtilities >>>> signalled err=-17102 at <>:1776 <<<< CMPhotoJFIFUtilities >>>> signalled err=-17102 at <>:1776 cicp_tagFromColorSpace:57: Failed to get CICP info for space: <CGColorSpace 0xc0a66b0c0> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1 <<<< CMPhotoJFIFUtilities >>>> signalled err=-17102 at <>:1776

System Console when running Moe's Image Viewer with filter set to ‘Moe’:

error 02:27:33.804783-0800 Moe's Image Viewer <<<< CMPhotoJFIFUtilities >>>> signalled err=-17102 at <>:1776 default 02:27:33.830529-0800 Moe's Image Viewer CGImageGetTransformForOrientationAndSize Invalid orientation parameter

Sorry I missed that detail. I'll do some more testing with your image and see what I can find.

Hello @elliotl,

We had an email discussion about this, hello again! 👋🏻

I'm going to share the context of that conversation so everyone is on the same page.

When we run the provided code, we only see warnings.

The warning does not occur when you use an RGB image, the image you provided is CMYK.

This thread discusses this topic and includes CMYK <-> RGB converters. https://developer.apple.com/forums/thread/763593

Thank you, I hope this helps!

 Travis Trotto - DTS Engineer

vImageBuffer_InitWithCGImage fails with Xcode 26 but succeeds with Xcode 15I am
 
 
Q