24

: CGContextSetFillColorWithColor: 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.

: CGContextSetStrokeColorWithColor: 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.

and similar errors repeated with:

  • CGContextSaveGState
  • CGContextSetFlatness
  • CGContextAddPath
  • CGContextDrawPath
  • CGContextRestoreGState
  • CGContextSaveGState
  • CGContextSetFlatness
  • CGContextAddPath
  • CGContextDrawPath
  • CGContextRestoreGState
  • CGContextSetFillColorWithColor
  • CGContextSetStrokeColorWithColor
  • CGContextSetFillColorWithColor
  • CGContextSetStrokeColorWithColor
  • CGContextGetBlendMode
  • CGContextSetBlendMode
  • and more...

In my App, I do not use any CGContext stuff. I just have a UITextView, UIButton and UILabel. Not much codes added yet. Just set the content of UITextView by:

[self.text_view setText:@"123"];

How to resolve the error ?

I'm using Xcode 5.0 (build 5A1413), iOS 7 Simulator (64-bit Retina 4"), Mac OS X 10.8.5

Raptor
  • 53,206
  • 45
  • 230
  • 366
  • I can reproduce this warning with a UITextField, but not a UITextView. The warning is still occurring in iOS 7.0.3. – bilobatum Oct 23 '13 at 22:03
  • Thanks for the information. I read from other thread that `UITextField` is also affected too, but none provided a valid solution. I think that's a false alarm. – Raptor Oct 24 '13 at 02:21
  • Was this issue ever solved? Im working on a Unity3D game currently for iOS, we get a very similar output of CG related Invalid state warnings, then the app dies. It only occurs randomly, and only when triggering native dialogs (we are trying to get our hands on the source code for our native dialogs plugin but from reading this post it seems more like an iOS issue with rendering text boxes?) – Fat-Wednesday Nov 12 '13 at 13:32
  • it's a known issue (after searching in Google, and Apple forum). Given that no new iOS SDK version has been released, this issue is remained unresolved, but not harmful. Probably false alarm. – Raptor Nov 13 '13 at 02:08
  • it is harmful to my app, not just false alarm, the UITextView gets cleared on this error. It's displaying one line of thousands of digits obtained from time consuming calculation, then when thumbing through the numbers it will clear with error. Quite serious when calculation can take hours. Hope an iOS update will soon fix! – colin lamarre Nov 18 '13 at 05:18
  • This is a known bug of iOS 7: http://stackoverflow.com/questions/19599266/invalid-context-0x0-under-ios-7-0-and-system-degradation – user3089080 Dec 11 '13 at 00:29
  • yes we know that. in rare case, it leads to app crash, while most cases, it remains harmless. – Raptor Dec 11 '13 at 07:31
  • This is currently an issue in iOS, and no workaround available at this time. For more information, check out the question here: http://stackoverflow.com/questions/19599266/invalid-context-0x0-under-ios-7-0-and-system-degradation – Roy Jay Dec 13 '13 at 18:40

3 Answers3

46

Try this: In xcode add symbolic breakpoint to CGPostError. (Add symbolic breakpoint, and to Symbol field type CGPostError)

When error happen, debugger will stop code executions and you can check stack of methods calls and check parameters.

Juraj Antas
  • 3,059
  • 27
  • 37
2

I had similar errors when using CGContext and UIBezierPaths, I used Juraj Antas' approach and I found the cause right away.

I am drawing on an UIImageView using CGContext. First I create a UIBezierPath then I draw it using CGContextAddPath(..). I found out the I was setting the color when creating the UIBezierPath, which xcode doesnt like and is anyways overwritten by CGContextSetStrokeColorWithColor(..). As soon as I removed the UIColor.whiteColor().set() from my UIBezierPath creation code, the errors were gone.

shnaz
  • 125
  • 2
  • 7
0

Thanks for the suggestion from @shnaz.

I ran into the same problem and it costed me some times until I could found a problem, wish my solution could help some others if they run into the same problem as well.

I probably didn't read the documentation thorough enough and I am new to creating UIBezierPath. It turns out in XCode6, .stroke() and .fill() will sometimes cause invalid context 0x0.

Jazi
  • 6,569
  • 13
  • 60
  • 92
Joey
  • 11
  • 2