I have a bit of a weird problem. I create a UIImage with imageNamed extract colour data from it and then set it to another class.
Then from that class when I do a drawRect I get an EXC_BAD_ACCESS when doing the drawRect.
Here is where I load the image:
UIImage* pImageHM = [UIImage imageNamed:@"Heatmap2.png"];
CGImageRef irHM = [pImageHM CGImage];
CFDataRef drHM = CGDataProviderCopyData( CGImageGetDataProvider( irHM ) );
R8G8B8A8* pDataHM = (R8G8B8A8*)CFDataGetBytePtr( drHM );
unsigned int colour = 0;
unsigned int colourMax = 256;
while( colour < colourMax )
{
// Extract image data.
colour++;
}
[mpView SetScale: pImageHM];
CFRelease( drHM );
CGImageRelease( irHM );
The SetScale function is defined as follows:
- (void) SetScale: (UIImage*)pImage
{
[mpScale release];
mpScale = pImage;
[mpScale retain];
[self setNeedsDisplay];
}
And finally I render it as follows:
CGContextRotateCTM( ctx, -M_PI_2 );
CGContextTranslateCTM( ctx, -(rect.size.height - 48), 0);
[mpScale drawInRect: CGRectMake( 0, rect.size.width - 16,
rect.size.height - 48, 16 )];
CGContextTranslateCTM( ctx, (rect.size.height - 48), 0 );
CGContextRotateCTM( ctx, M_PI_2 );
Why would the mpScale raise an EXC_BAD_ACCESS? Given the UIImage has been retained the fact it was subsequently autoreleased after I had called SetScale should be neither here nor there.
I should add that if I don’t call SetScale (such that mpScale remains as nil) then I get no crash and, obviously, I don’t see anything where the scale ought to be.
Thanks in advance!
CGImageRef irHM = [pImageHM CGImage];You do not own this CGImage, but you are releasing it.
CGImageRelease( irHM );