本文介绍了崩溃CGDataProviderCreateWithCopyOfData:vm_copy失败:状态1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我遇到以下错误而导致的崩溃:我有多个问题,您可以帮忙。 vm_copy中的状态1代表什么失败? 这个崩溃发生只有当我在数据复制的内循环中设置断点时。然后恢复并删除断点。如果没有断点,函数执行,但我得到一个空白图像。 当我执行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 { 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; } 解决方案 a href =http://www.opensource.apple.com/source/xnu/xnu-1456.1.26/osfmk/mach/kern_return.h =nofollow> kern_return.h 头文件: #define KERN_INVALID_ADDRESS 1 / *指定的地址目前无效。 * / 这对应于与 vm_copy相关的错误代码失败:状态1 我怀疑这是一个与内存对齐相关的问题,因为 vm_copy文档说明地址[es]必须在页面边界 要确保使用正确对齐的缓冲区,您应该使用相同的方式分配 piData 输入图片: size_t bytesPerRow = CGImageGetBytesPerRow(inImage ); UInt8 * piData = calloc(bytesPerRow * height,sizeof(UInt8)); 然后使用 bytesPerRow 循环中的中的code> width * 4 ,即: iStep = i * bytesPerRow; 这应该可以解决你的问题(注意:我假设 CGImageGetWidth 和 width 是相同的)。 I am facing a crash with following error:I have multiple questions and you can help.What does status 1 stand for in vm_copy failed?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?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;} 解决方案 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). 这篇关于崩溃CGDataProviderCreateWithCopyOfData:vm_copy失败:状态1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-17 14:32