Q:

iPhone cannot create CGBitmapContext

I have a problem with creating a CGBitmapContext.
CGContextRef bitmapContext = CGBitmapContextCreate(nil, imageSize.width, imageSize.height, 8, imageSize.width * 4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst)

When I run my application normally it works. But when I run it in my 'Test application' (a running app that will perform my tests) the context is logged as (null) and I get the following errors:
<Error>: CGContextSetFillColorWithColor: invalid context 0x0
<Error>: CGContextFillRects: invalid context 0x0
<Error>: CGContextDrawImage: invalid context 0x0
<Error>: CGContextDrawImage: invalid context 0x0
<Error>: CGBitmapContextCreateImage: invalid context 0x0

My application doesn't crash. But apparently there is something wrong. (I know the errors are created by calling those methods with a nil context).

A:

This error often appears when the size of the bitmap you're trying to create is CGSizeZero. Check the actual value of imageSize.
Besides, you leak the CGColorSpaceRef you pass into the function.

