Reputation: 5098
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).
Upvotes: 5
Views: 4130
Reputation: 70743
Do you check for the CGBitmapContextCreate return value to be non-nil? You will get a nil value if there isn't enough memory available on the device to create the context.
How much memory are you using in the app and for what size bitmap are you asking?
Upvotes: 0
Reputation: 23722
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.
Upvotes: 7