大きなPNG画像の束をピクセルごとに解析する必要がある方法があります(PNGはそれぞれ600x600ピクセルです)。Simulator では問題なく動作するようですが、デバイス (iPad) では、一部の内部メモリ コピー関数で EXC_BAD_ACCESS が発生します。小さい画像で試してみると、すべてがうまくいくように見えるので、サイズが原因のようです。これは、以下のメソッドのメモリ関連の肉です。
+ (CGRect) getAlphaBoundsForUImage: (UIImage*) image
{
CGImageRef imageRef = [image CGImage];
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = malloc(height * width * 4);
memset(rawData,0,height * width * 4);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * width;
NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
CGContextRelease(context);
/* non-memory related stuff */
free(rawData);
これを一連の画像で実行すると、12回実行されてから失敗しますが、シミュレーターでは問題なく実行されます。何かアイデアはありますか?