title: dismissModalViewControllerAnimated: (and dismissViewControllerAnimated) crashing in iOS 5
body: <p>I can't find any logical explanation, but the fact remains that, in iOS 5 (xCode 4.2), if I presentModalView:* animated:YES, I can call dismissModalViewAnimated:* fine, but if I call presentModalView:* animated:NO, then calling the dismiss method crashes. (This works the same if I use the new presentViewController:animated:completion: + dismissViewControllerAnimated:). I am going TRY to work around this for now (I don't want the presentation animated) and report a bug to Apple, but I have been beating my head on this for a while. Any and all suggestions are welcome. Not much out there on iOS 5, so please help if you can. Sample code that does not crash in iOS 4 or iOS 5:</p>
  
  <pre><code>LoginController *loginController = [[LoginController alloc] initWithNibName:@"LoginControllerGG" bundle:nil];
  [self presentModalViewController:loginController animated:YES];
  [loginController release];
  ...
  [self dismissModalViewControllerAnimated:YES];
  </code></pre>
  
  <p>This will crash in iOS 5 with EXC_BAD_ACCESS on the dismiss call:</p>
  
  <pre><code>LoginController *loginController = [[LoginController alloc]    initWithNibName:@"LoginControllerGG" bundle:nil];
  [self presentModalViewController:loginController animated:NO];
  [loginController release];
  ...
  [self dismissModalViewControllerAnimated:YES]; //crashes with EXC_BAD _ACCESS
  </code></pre>
  
  <p>One note: I have an animation within the loginController that happens on viewDidLoad. Going to see if taking that out changes anything, but I wanted to get this out there since I need a solution asap. </p>
  
  <hr>
  
  <p>[Edit] Full code flow... In AppDelegate, application:didFinishLaunchingWithOptions:</p>
  
  <pre><code>if (!loggedIn)  [myViewController showLoginPanel];
  </code></pre>
  
  <p>In myViewController:</p>
  
  <pre><code>- (void)showLoginPanel {    
      LoginController *loginController = [[LoginController alloc] initWithNibName:@"LoginControllerGG" bundle:nil];
      if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]) {
          [self presentViewController:loginController animated:NO completion:nil];
      } else {
          [self presentModalViewController:loginController animated:NO]; //iOS 4 works fine with or without animation   
      } 
      [loginController release];  
  }
  </code></pre>
  
  <p>In loginController:</p>
  
  <pre><code>- (IBAction)closeLoginWindow {
      [[NSNotificationCenter defaultCenter] postNotificationName:@"CloseLoginWindow" object:nil];
  }   //doing it this way because calling on the self.parentViewController doesn't work
  </code></pre>
  
  <p>Back in myViewController:</p>
  
  <pre><code>- (void) viewDidLoad
      ...
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeLoginWindow) name:@"CloseLoginWindow" object:nil];
      ...
  
  - (void)closeLoginWindow {
      if ([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) {
          [self dismissViewControllerAnimated:YES completion:nil];    //iOS 5 crashes only if presentation was not animated
      } else [self dismissModalViewControllerAnimated:YES];    //deleting the previous condition, iOS 5 still crashes if presentation was not animated
  }    
  </code></pre>