mindbrix / UIImage-PDF

Simple UIImage PDF renderer category for iOS scalable assets
http://blog.mindbrix.co.uk/2012/02/10/ios-scalable-assets/
1.24k stars 155 forks source link

Invalid context #27

Closed ghost closed 10 years ago

ghost commented 10 years ago

I noticed this had been raised in February but then closed in March unresolved.

I'm getting this warning in Xcode console:

: CGContextTranslateCTM: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update. when PDFView.m hits the line: CGContextGetCTM( ctx ); in RenderIntoContext:url:data:size:page: Looking at the values being passed to this, ctx is nil. The code I'm using to call the library is standard: [self.convertButton setImage:[UIImage imageWithPDFNamed:@"convert_button.pdf" atSize:self.convertButton.frame.size] forState:UIControlStateNormal]; Any help with this appreciated, as it's firing off multiple warnings every time I use a PDF. This is in iOS7.
mindbrix commented 10 years ago

Hi @stickytroll, thanks for the report. I suspect the calls to UIGraphicsBeginImageContextWithOptions() and UIGraphicsGetCurrentContext are failing, possibly a bug in UIKit.

I need to switch over to using CGBitmapContextCreate().

mindbrix commented 10 years ago

@stickytroll, have you checked that self.convertButton.frame.size is non-zero?

ghost commented 10 years ago

Hi, yes the frame size is non-zero. The image is being created (and cached) at the correct size of the button's frame.

mindbrix commented 10 years ago

Hi. I've made some changes to the code. Can you see if you still get the error?

ghost commented 10 years ago

The latest code seems to be working fine, without any warnings... What was the issue?

mindbrix commented 10 years ago

My guess is that UIGraphicsBeginImageContextWithOptions() was failing, so I replaced it with the Core Graphics equivalents. I've also added more parameter validation.

Thanks for your help ;-)