Mac OSX Yosemite에서 CGContextDrawImage를 사용하여 CGImageRef를 그려 봅니다. 내 이미지가 너비가 균일 할 때 모든 것이 잘 작동하지만 홀수 인 경우 EXC_BAD_ACCESS로 프로그램이 충돌합니다. 모든 것이 정상적으로 보일지라도 (이미지와 비트 맵 컨텍스트가 메모리에 있음). 충돌이 나타나면CGContextDrawImage가 홀수 너비 값과 충돌합니다.
unsigned long rowBytes = ((CGImageGetBitsPerPixel(image) * CGImageGetWidth(image)) + 15) & ~15;
/* TRIED THIS WITH SAME RESULTS
unsigned long rowBytes = CGImageGetWidth(image) * 4;
if (rowBytes % 16) {
rowBytes = ((rowBytes/16) + 1) * 16;
}
*/
void *baseAddress = valloc(CGImageGetHeight(image) * rowBytes);
if (baseAddress == NULL) {
CGImageRelease(image);
return nil;
}
CGContextRef bitmapContext = CGBitmapContextCreate(baseAddress,
CGImageGetWidth(image),
CGImageGetHeight(image),
8,
rowBytes,
[context colorSpace],
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);
if (bitmapContext == NULL) {
free(baseAddress);
CGImageRelease(image);
return nil;
}
CGRect bounds = CGRectMake(0, 0, CGImageGetWidth(image), CGImageGetHeight(image));
CGContextClearRect(bitmapContext, bounds);
CGContextDrawImage(bitmapContext, bounds, image);
에서, libRIP 라이브러리는 이러한 메시지와 관련된 것으로 보인다 : 0 추락
스레드 :: 파견 큐 : com.apple
여기 내 코드입니다. decode_data + 19,394 2 com.apple.CoreGraphics 0x00007fff81234c84 img_decode_read 0x00007fff8123a2af 메인 쓰레드 0
com.apple.CoreGraphics 0x00007fff8124aaa0 decode_byte_8bpc_3는 375 + 1 com.apple.CoreGraphics 380 + 3 com.apple.CoreGraphics
0x00007fff812349ff img_colormatch_read + 379 4
com.apple.CoreGraphics 0x00007fff8121a40d img_data_lock + 8512 CGSImageDataLock 0x00007fff8121726e 5 com.apple.CoreGraphics는 + 151 6 libRIP.A.dylib 0x00007fff8c8d52d2 ripc_AcquireImage + 906 7 libRIP .A.dylib
0x00007fff8c8d3df5 ripc_DrawImage + 1037 8 com.apple.CoreGraphics
0x00007fff81216e27 CGContextDrawImage +
457 나는이 행 바이트 값 문제 만이 값이 실패로 관리 할 수있는 모든 노력을 생각했다. 누구든지 동일한 문제가 있었고 해결 했습니까? 내가 뭘 놓치고 있니?
현재 계산 중 (CGImageGetBitsPerPixel (이미지) * CGImageGetWidth (이미지)) +15) & ~ 15'은 바이트가 아닌 행당 ** 비트를 계산합니다. 어떤 경우에는, 특정 바이트 수를 강제하지 않는 한,'data' 매개 변수에'NULL'을,'CGBitmapContextCreate()'의'bytesPerRow' 매개 변수에 0을 전달해야합니다. 버퍼에 저장하고 행당 최적의 바이트를 계산합니다. 마지막으로 스택 추적에서 비트 맵 컨텍스트가 아니라 소스 이미지에 문제가 있다고 생각합니다. CG는 그릴 때까지 데이터를 사용하여 연기했을 수 있으므로 문제가 발생할 수 있습니다. –