Under what circumstances will a CGBitmapContext fail to allocate? I have a table view, and it has multiple view options. The user can see a small table cell with just previews, one larger preview per line, or two side by side previews per line. The first two render just fine, but the third one fails. There are no error messages from CGBitmapContextCreate, just errors after when I try to use it (i.e. invalid context 0x0).
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
//size is a passed parameter
CGContextRef c = CGBitmapContextCreate(NULL, size.width, size.height, 8, size.width*4, colorSpace, kCGImageAlphaNoneSkipLast);
CGColorSpaceRelease(colorSpace);
I am targeting iOS 5.0, building with 5.1. The only difference between the working and non-working version is that the non-working version attempts to do it twice (size is small, less than 100x100). Only the right side has this problem (i.e. the second attempt). The first attempt still works.
This can happen if
size.width
and/orsize.height
is 0. Put aNSLog
to check the sizes every time you call this method to see if that's the case.