Error Message in Debug Area

With every playground that runs in Xcode 7.0 beta 5, the following three errors display in the debug area:

Aug 6 13:11:50 Tour1[17353] <Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

Aug 6 13:11:50 Tour1[17353] <Error>: CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

Aug 6 13:11:50 Tour1[17353] <Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.


How do I fix this? How do I set the environmental variables and what do I set them to?

Replies

No solution yet.

I had the same issue. Was generating barcode and sometimes context was 0x0.

The problem was that i was begining an image context with height == 0.0


Because the source of the size was an UIImageView placed on UIStackView and when hidden its height was 0.0f. When i was trying to set image created depending on the image view size, an invalid size (before setting its hidden property to NO, and layouting) for context the UIGraphicsGetCurrentContext() was returning null.


An example:

CGSize size = ciImage.extent.size; // for eg. {320.0, 0.0}
UIGraphicsBeginImageContextWithOptions(size, true, [UIScreen mainScreen].scale);
CGContextRef cgContext = UIGraphicsGetCurrentContext(); // cgContext == 0x0


So I recommand to debug and make sure that you are not facing the same case.