Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crash CGDataProviderCreateWithCopyOfData: vm_copy failed: status 1

I am facing a crash with following error:

"CGDataProviderCreateWithCopyOfData: vm_copy failed: status 1."

I have multiple questions and you can help.

  1. What does status 1 stand for in vm_copy failed?

  2. This crash happens only when I set a break point in the inner for loop of data copy. And then resume and remove the breakpoint. If there is no breakpoint, function executes but I get a blank image. How do I ensure that even if I don't set a break point, such crashes are caught and application stops execution?

  3. This error comes when I execute CGBitmapContextCreateImage. Does anyone know how to resolve this?

-(UIImage *) convertBitmapRGBA8ToUIImage:(UInt8**)img 
                                    :(int) width
                                    :(int) height 
{

CGImageRef inImage = m_inFace.img.CGImage;

UInt8*piData = calloc( width*height*4,sizeof(UInt8));

int iStep,jStep;
for (int i = 0; i < height; i++) 
{
    iStep = i*width*4;
    for (int j = 0; j < width; j++) 
    {
        jStep = j*4;
        piData[iStep+jStep] =img[i][j];
        piData[iStep+jStep+1] =img[i][j];
        piData[iStep+jStep+2] = img[i][j];

    }
}

CGContextRef ctx = CGBitmapContextCreate(piData,
                                         CGImageGetWidth(inImage),  
                                         CGImageGetHeight(inImage),  
                                         CGImageGetBitsPerComponent(inImage),
                                         CGImageGetBytesPerRow(inImage),  
                                         CGImageGetColorSpace(inImage),  
                                         CGImageGetBitmapInfo(inImage) 
                                         ); 

CGImageRef imageRef = CGBitmapContextCreateImage(ctx);  
UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
CGContextRelease(ctx);
CGImageRelease(imageRef);
free(piData);
return finalImage;

}
like image 727
TorukMakto Avatar asked Oct 27 '12 12:10

TorukMakto


1 Answers

The kern_return.h header file gives:

#define KERN_INVALID_ADDRESS        1
  /* Specified address is not currently valid.
   */

This corresponds to the error code related to vm_copy failed: status 1.

I suspect this is a problem related to memory alignment, since the vm_copy documentation states that address[es] must be on a page boundary.

To make sure you work with properly aligned buffers, you should allocate your piData buffer with the same stride than your inImage input image:

size_t bytesPerRow = CGImageGetBytesPerRow(inImage);
UInt8*piData = calloc(bytesPerRow*height,sizeof(UInt8));

Then use this bytesPerRow value instead of width*4 within your for loop, i.e:

iStep = i*bytesPerRow;

This should solve your problem (Note: I assume that CGImageGetWidth(inImage) and width are the same).

like image 160
deltheil Avatar answered Sep 29 '22 00:09

deltheil