8

我正面临以下错误的崩溃:

“CGDataProviderCreateWithCopyOfData:vm_copy 失败:状态 1。”

我有多个问题,你可以帮忙。

  1. vm_copy failed 中的状态 1 代表什么?

  2. 仅当我在数据副本的内部 for 循环中设置断点时,才会发生此崩溃。然后恢复并删除断点。如果没有断点,函数会执行但我得到一个空白图像。如何确保即使我没有设置断点,也能捕获此类崩溃并且应用程序停止执行?

  3. 当我执行 CGBitmapContextCreateImage 时出现此错误。有谁知道如何解决这个问题?

-(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;

}
4

1 回答 1

5

kern_return.h文件给出:

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

这对应于相关的错误代码vm_copy failed: status 1

我怀疑这是与内存对齐有关的问题,因为vm_copy 文档指出address[es] must be on a page boundary

为了确保您使用正确对齐的缓冲区,您应该piData以与inImage输入图像相同的步幅分配缓冲区:

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

然后使用这个bytesPerRow值而不是width*4在你的for循环中,即:

iStep = i*bytesPerRow;

这应该可以解决您的问题(注意:我假设CGImageGetWidth(inImage)width是相同的)。

于 2012-10-28T10:58:57.177 回答