62 Replies
      Latest reply on Sep 18, 2017 8:20 AM by g.m.
      klmg Level 1 Level 1 (0 points)

        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?

        • Re: Error Message in Debug Area
          haptic Level 1 Level 1 (0 points)

          Hello, klmg, You are not the only one. This popped up in my Xcode 7.0 beta 5 project as well. Please file a bug report and share the number here. Thank you.

          • Re: Error Message in Debug Area
            MarcS Level 1 Level 1 (0 points)

            Hi,

             

            same problem here.

            Playground with OS X target is working for me

            • Re: Error Message in Debug Area
              Trifusion Level 1 Level 1 (10 points)

              Same problem

               

              Greg

              • Re: Error Message in Debug Area
                johnt519 Level 1 Level 1 (0 points)

                See it to, on iOS, not OSX.

                 

                Also, in the console, when the playground executes, it spews out:

                 

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                8/7/15 9:15:30.000 PM kernel[0]: Sandbox: MyPlayground(45970) deny ipc-posix-shm-read-data apple.sim.cfprefsd.daemon

                • Re: Error Message in Debug Area
                  JackL Apple Staff Apple Staff (85 points)

                  This is a known issue when running iOS playgrounds, thank you for your bug reports!

                  • Re: Error Message in Debug Area
                    ikeDonG Level 1 Level 1 (0 points)

                    I got the same problem, it seems to be the problem on iOS9 Beta 5. I use Xcode 7 beta 6 to run against iOS8 and it is fine.

                    • Re: Error Message in Debug Area
                      dcaldwell_payzoom Level 1 Level 1 (0 points)

                      BACKTRACE:

                      Sep  1 16:50:04  WorkAids2[1627] <Error>: CGContextSaveGState: invalid context 0x0. Backtrace:

                          <<redacted>+34>

                          <<redacted>+398>

                            <<redacted>+120>

                            <<redacted>+142>

                              <<redacted>+318>

                              <<redacted>+82>

                                <<redacted>+770>

                                <<redacted>+842>

                                  <<redacted>+352>

                                  <<redacted>+72>

                                    <<redacted>+788>

                                    <<redacted>+328>

                                      <<redacted>+400>

                                      <<redacted>+96>

                                        <<redacted>+90>

                                        <<redacted>+278>

                                          <<redacted>+502>

                                          <<redacted>+426>

                                            <<redacted>+1606>

                                            <<redacted>+30>

                                              <<redacted>+240>

                                              <<redacted>+286>

                                                <<redacted>+858>

                                                <<redacted>+36>

                                                  <<redacted>+134>

                                                  <<redacted>+232>

                                                    <<redacted>+44>

                                                    <<redacted>+14>

                                                      <<redacted>+454>

                                                      <<redacted>+806>

                                                        <CFRunLoopRunSpecific+516>

                                                        <CFRunLoopRunInMode+108>

                                                          <<redacted>+526>

                                                          <UIApplicationMain+144>

                                                            <main+108>


                      mmmnnn very helpful...


                      • Re: Error Message in Debug Area
                        logi Level 1 Level 1 (0 points)

                        I am getting the following errors in Playground with the latest Xcode 7 GM, OS X 10.11 GM and iOS 9 GM, any possible solution to get rid of them?

                         

                        Sep  9 21:59:09  SwiftPlayground[1045] <Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

                        Sep  9 21:59:09  SwiftPlayground[1045] <Error>: CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

                        Sep  9 21:59:09  SwiftPlayground[1045] <Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

                        • Re: Error Message in Debug Area
                          Beto_Bens Level 1 Level 1 (0 points)

                          Remove UIViewControllerBasedStatusBarAppearance (View controller-based status bar appearance) from Info.plist fixed it for me.

                          • Re: Error Message in Debug Area
                            jtca Level 1 Level 1 (0 points)

                            Removing UIViewControllerBasedStatusBarAppearance removes the error display, however I think it's related to the UIApplication statusBar methods deprecations. I don't see any replacements for them. I've never been able to see a light status bar without that key.

                             

                            https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIApplication_Class/index.html#//apple_ref/doc/uid/TP40006728-CH3-SW170

                            • Re: Error Message in Debug Area
                              JohnBear Level 1 Level 1 (0 points)

                              Hi,

                                   I encounter this problem too, at the starting of APP after upgrading to xcode 7.

                                   After all, i found the reason of problem, custom font - Helvetica Neue was used in some xibs of the project. I replace the custom font by system font, everything is ok.

                                   I hope my reply would help someone with the same problem.

                               

                              John from 360.

                              • Re: Error Message in Debug Area
                                OsakaStarbux Level 1 Level 1 (0 points)

                                I get this error as soon as I open a new blank iOS playground in Xcode 7 GM

                                • Re: Error Message in Debug Area
                                  Digicub Level 1 Level 1 (0 points)

                                  I get this with XCode7 and iOS9 release.

                                   

                                  I can't remove UIViewControllerBasedStatusBarAppearance because then the status bar returns!

                                  • Re: Error Message in Debug Area
                                    diego_moving Level 1 Level 1 (0 points)

                                    If View controller-based status bar appearance is NO, just replace to YES.

                                    Just that.

                                     

                                    Tnks.

                                      • Re: Error Message in Debug Area
                                        peacetype Level 1 Level 1 (0 points)

                                        Changing UIViewControllerBasedStatusBarAppearance (View controller-based status bar appearance) from NO to YES made the error messages go away for me. However, this also prevented my app from using the light colored status bar (statusBarStyle = .LightContent), which is needed for my app's UI. As jtca pointed out, statusBarStyle has been deprecated in iOS 9.0 but without any apparent replacement.

                                         

                                        It is good to know that we can ignore these warnings, as JackL said. But I did file bug report number 22752045. Hopefully this gets fixed.

                                      • Re: Error Message in Debug Area
                                        Runcible Level 1 Level 1 (0 points)

                                        This is happening for me in Playgrounds, as it was for the person who made the original post.

                                         

                                        Does the info.plist file affect the Playgrounds?

                                         

                                        I didn't think so--and if not, altering it won't make the bug go away.

                                        • Re: Error Message in Debug Area
                                          fewspider Level 1 Level 1 (0 points)

                                          any solution?

                                          • Re: Error Message in Debug Area
                                            davidtoledo Level 1 Level 1 (0 points)

                                            Same problem with xcode Version 7.0 (7A220)

                                             

                                            any solution?

                                            • Re: Error Message in Debug Area
                                              minikin Level 1 Level 1 (0 points)

                                              Xcode  7.0.1 (7A1001)

                                              any news?

                                              • Re: Error Message in Debug Area
                                                vgranada Level 1 Level 1 (0 points)

                                                someone has tested with Xcode 7.0.1 Beta 3 (7B85)?

                                                • Re: Error Message in Debug Area
                                                  leisuremonkey Level 1 Level 1 (0 points)

                                                  Luckily this finally appears to be resolved in Xcode 7.1, at least for me.

                                                  • Re: Error Message in Debug Area
                                                    marioooooo Level 1 Level 1 (0 points)

                                                    Hey Guys, I got a fix for this issue

                                                     

                                                    Go to your app-info.plist. And add

                                                     

                                                    <key>NSAppTransportSecurity</key>

                                                        <dict>

                                                            <key>NSAllowsArbitraryLoads</key>

                                                            <true/>

                                                        </dict>

                                                    • Re: Error Message in Debug Area
                                                      vgranada Level 1 Level 1 (0 points)

                                                      Hi,

                                                       

                                                      on 10/29/2015 Apple sent me an email stating that he had already solved this bug.

                                                       

                                                      Fortunately the error was not with my project. Unfortunately Apple took one month to recognize and resolve the issue.

                                                      • Re: Error Message in Debug Area
                                                        ThePawel Level 1 Level 1 (0 points)

                                                        Xcode Version 7.2 (7C68) - problem still occurs.

                                                        • Re: Error Message in Debug Area
                                                          marco_bobo Level 1 Level 1 (0 points)

                                                          Xcode 7.2 still exists

                                                          <Error>: CGContextRestoreGState: invalid context 0x0. Backtrace:

                                                              <-[CUSFlashLabel drawRect:]+912>

                                                              <<redacted>+368>

                                                                <<redacted>+260>

                                                                <<redacted>+2364>

                                                                  <<redacted>+1224>

                                                                  <<redacted>+228>

                                                                    <<redacted>+44>

                                                                    <<redacted>+252>

                                                                      <<redacted>+512>

                                                                      <<redacted>+80>

                                                                        <<redacted>+32>

                                                                        <<redacted>+372>

                                                                          <<redacted>+928>

                                                                          <CFRunLoopRunSpecific+384>

                                                                            <GSEventRunModal+180>

                                                                            <UIApplicationMain+204>

                                                                              <main+124>

                                                          • Re: Error Message in Debug Area
                                                            MoacirLamego Level 1 Level 1 (0 points)

                                                            Hi,

                                                             

                                                            Xcode Version 7.3 (7D175) - problem still occurs.

                                                            • Re: Error Message in Debug Area
                                                              MaheshSheliya Level 1 Level 1 (0 points)

                                                              Any solution ?

                                                               

                                                              I got problems in xcode 8.0 beta.

                                                              • Re: Error Message in Debug Area
                                                                g.m. Level 1 Level 1 (0 points)

                                                                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.