title: Crash if backgrounding cocos2d 2.1 app in iOS7 while watching Game Center screens (leaderboard, achievement)
body: <p>I have a 100% reproducible crash here.</p>
  
  <p>Crash if backgrounding cocos2d 2.1 app in iOS7 while watching Game Center screens (leaderboard, achievement). It crashes instantly when pushing the home button.</p>
  
  <p>Crash on line 275 in CCGLView.m:</p>
  
  <pre><code>if(![_context presentRenderbuffer:GL_RENDERBUFFER])
  </code></pre>
  
  <p>The itching thing is, I downloaded a fresh copy of official cocos2diphone 2.1 the other second, installed its templates and ran the staple application after hooking it up to the same app id as my problematic app that already have game center leaderboards etc set up. It does not crash. So I ran a diff on the cocos2d folders inside lib, and there is no difference except I added some C functions code in CCDrawingPrimitives.h/m... Should not be the problem.
  So the problem should not be in cocos2d itself but somehow the use of it or my project setup causes it.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>The problem seems to be in the cocos2d app template in use in 2.1 and possibly earlier. It looks like this:</p>
  
  <pre><code>-(void) applicationDidEnterBackground:(UIApplication*)application
  {
      if( [navController_ visibleViewController] == director_ )
          [director_ stopAnimation];
  }
  </code></pre>
  
  <p>And the obvious fault here is that if you have navController open a Game Center controller, then when pushing the home button the visibleViewController of director_ will be the GC controller, hence the stopAnimation will not get called. This results in a crash with iOS7, but doesn't seem to with iOS6... nor the template cocos2d 2.1 app (still confused here).</p>
  
  <p>The current fix is to comment out <code>if( [navController_ visibleViewController] == director_ )</code> in order to have stopAnimation always called. Not sure if there are any side effects with that but will go with this for now.</p>