We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4470

Summary: CGContext: invalid context 0x0
Product: SDL Reporter: sabino.paulicelli
Component: renderAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: amaranth72, pauli.jokela, seant29373
Version: 2.0.9   
Hardware: x86_64   
OS: Other   

Description sabino.paulicelli 2019-01-24 20:00:00 UTC
Cannot clear with a renderer.
Issue on Mac OS X 10.14 (.2 and .3)

xcode log:
2019-01-24 20:51:47.317633+0100 SDL-Swift-Game-Engine[9020:334746] [SDL-Swift-Game-Engine] CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2019-01-24 20:51:47.317687+0100 SDL-Swift-Game-Engine[9020:334746] [SDL-Swift-Game-Engine] CGContextGetCompositeOperation: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2019-01-24 20:51:47.317703+0100 SDL-Swift-Game-Engine[9020:334746] [SDL-Swift-Game-Engine] CGContextSetCompositeOperation: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2019-01-24 20:51:47.317714+0100 SDL-Swift-Game-Engine[9020:334746] [SDL-Swift-Game-Engine] CGContextFillRects: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
2019-01-24 20:51:47.317730+0100 SDL-Swift-Game-Engine[9020:334746] [SDL-Swift-Game-Engine] CGContextSetCompositeOperation: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

Also reported (unanswered) on Stack Overflow at https://stackoverflow.com/q/53963463/4242891
Comment 1 sabino.paulicelli 2019-01-24 20:01:08 UTC
Sorry for any mistake or missed info. This is my first bug report.

:]
Comment 2 sabino.paulicelli 2019-01-24 20:21:15 UTC
I also replicated this using the example at https://wiki.libsdl.org/SDL_CreateRenderer written in C
Comment 3 Sean 2019-04-28 13:50:32 UTC
I'm getting the same error on OSX Mojave 10.14.4.

If I set the environment variable CG_CONTEXT_SHOW_BACKTRACE=1, then I get a larger stack trace:

2019-04-28 09:20:38.220672-0400 game[17831:2297463] [game] CGContextSetFillColorWithColor: invalid context 0x0. Backtrace:
  <_setColorWithFillAndStroke+152>
   <-[SDLView drawRect:]+45>
    <-[_NSOpenGLViewBackingLayer display]+901>
     <_ZN2CA5Layer17display_if_neededEPNS_11TransactionE+627>
      <_ZN2CA7Context18commit_transactionEPNS_11TransactionE+342>
       <_ZN2CA11Transaction6commitEv+588>
        <__65+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayRefresh]_block_invoke+274>
         <__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__+23>
          <__CFRunLoopDoObservers+451>
           <__CFRunLoopRun+1136>
            <CFRunLoopRunSpecific+455>
             <RunCurrentEventLoopInMode+292>
              <ReceiveNextEventCommon+355>
               <_BlockUntilNextEventMatchingListInModeWithFilter+64>
                <_DPSNextEvent+965>
                 <-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]+1361>
                  <Cocoa_PumpEvents+138>
                   <SDL_WaitEventTimeout_REAL+203>
                    <event_pump+59>
                     <event_loop+768>
                      <main+2067>
                       <start+1>                               1
2019-04-28 09:20:38.223688-0400 game[17831:2297463] [game] CGContextGetCompositeOperation: invalid context 0x0. Backtrace:
  <CGContextGetCompositeOperation+45>
   <NSRectFill+154>
    <-[SDLView drawRect:]+70>
     <-[_NSOpenGLViewBackingLayer display]+901>
      <_ZN2CA5Layer17display_if_neededEPNS_11TransactionE+627>
       <_ZN2CA7Context18commit_transactionEPNS_11TransactionE+342>
        <_ZN2CA11Transaction6commitEv+588>
         <__65+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayRefresh]_block_invoke+274>
          <__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__+23>
           <__CFRunLoopDoObservers+451>
            <__CFRunLoopRun+1136>
             <CFRunLoopRunSpecific+455>
              <RunCurrentEventLoopInMode+292>
               <ReceiveNextEventCommon+355>
                <_BlockUntilNextEventMatchingListInModeWithFilter+64>
                 <_DPSNextEvent+965>
                  <-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]+1361>
                   <Cocoa_PumpEvents+138>
                    <SDL_WaitEventTimeout_REAL+203>
                     <event_pump+59>
                      <event_loop+768>
                       <main+2067>
                        <start+1>                                1
2019-04-28 09:20:38.224341-0400 game[17831:2297463] [game] CGContextSetCompositeOperation: invalid context 0x0. Backtrace:
  <NSRectFill+209>
   <-[SDLView drawRect:]+70>
    <-[_NSOpenGLViewBackingLayer display]+901>
     <_ZN2CA5Layer17display_if_neededEPNS_11TransactionE+627>
      <_ZN2CA7Context18commit_transactionEPNS_11TransactionE+342>
       <_ZN2CA11Transaction6commitEv+588>
        <__65+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayRefresh]_block_invoke+274>
         <__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__+23>
          <__CFRunLoopDoObservers+451>
           <__CFRunLoopRun+1136>
            <CFRunLoopRunSpecific+455>
             <RunCurrentEventLoopInMode+292>
              <ReceiveNextEventCommon+355>
               <_BlockUntilNextEventMatchingListInModeWithFilter+64>
                <_DPSNextEvent+965>
                 <-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]+1361>
                  <Cocoa_PumpEvents+138>
                   <SDL_WaitEventTimeout_REAL+203>
                    <event_pump+59>
                     <event_loop+768>
                      <main+2067>
                       <start+1>                               1
2019-04-28 09:20:38.224992-0400 game[17831:2297463] [game] CGContextFillRects: invalid context 0x0. Backtrace:
  <CGContextFillRect+105>
   <NSRectFill+237>
    <-[SDLView drawRect:]+70>
     <-[_NSOpenGLViewBackingLayer display]+901>
      <_ZN2CA5Layer17display_if_neededEPNS_11TransactionE+627>
       <_ZN2CA7Context18commit_transactionEPNS_11TransactionE+342>
        <_ZN2CA11Transaction6commitEv+588>
         <__65+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayRefresh]_block_invoke+274>
          <__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__+23>
           <__CFRunLoopDoObservers+451>
            <__CFRunLoopRun+1136>
             <CFRunLoopRunSpecific+455>
              <RunCurrentEventLoopInMode+292>
               <ReceiveNextEventCommon+355>
                <_BlockUntilNextEventMatchingListInModeWithFilter+64>
                 <_DPSNextEvent+965>
                  <-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]+1361>
                   <Cocoa_PumpEvents+138>
                    <SDL_WaitEventTimeout_REAL+203>
                     <event_pump+59>
                      <event_loop+768>
                       <main+2067>
                        <start+1>                                1
2019-04-28 09:20:38.225645-0400 game[17831:2297463] [game] CGContextSetCompositeOperation: invalid context 0x0. Backtrace:
  <NSRectFill+252>
   <-[SDLView drawRect:]+70>
    <-[_NSOpenGLViewBackingLayer display]+901>
     <_ZN2CA5Layer17display_if_neededEPNS_11TransactionE+627>
      <_ZN2CA7Context18commit_transactionEPNS_11TransactionE+342>
       <_ZN2CA11Transaction6commitEv+588>
        <__65+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayRefresh]_block_invoke+274>
         <__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__+23>
          <__CFRunLoopDoObservers+451>
           <__CFRunLoopRun+1136>
            <CFRunLoopRunSpecific+455>
             <RunCurrentEventLoopInMode+292>
              <ReceiveNextEventCommon+355>
               <_BlockUntilNextEventMatchingListInModeWithFilter+64>
                <_DPSNextEvent+965>
                 <-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]+1361>
                  <Cocoa_PumpEvents+138>
                   <SDL_WaitEventTimeout_REAL+203>
                    <event_pump+59>
                     <event_loop+768>
                      <main+2067>
                       <start+1>                               1


(tart, main, event_loop, and event_pump is all my code... I'm calling SDL_PollEvent inside event_pump)
Comment 4 Alex Szpakowski 2019-10-14 03:53:32 UTC
https://hg.libsdl.org/SDL/rev/065b94926987 should fix it.