Edit: It seems this was a stupid mistake by me, i got a rotationChanged notification too early, before i could process it. That caused a chain reaction which caused a crash in some obscure location. Let me see how i can close/delete this question…
My app’s been working fine for a while, but i decided today to finally implement it ‘correctly’, that is: Use a view controller instead of manually adding a single view to the UIWindow. This went quite smooth for a while, untill i tried setting window.rootViewController to my view controller.
Somewhere after applicationDidFinishLaunchingWithOptions, it crashes with a bad access. There’s no useful stacktrace (it crashes in the assembly), and i can’t see it getting back into my code anywhere (i placed logs all over the place). Just adding the viewcontroller’s view to the main window works fine. This is the part of the code:
-(BOOL) application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
....
self.window = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];
self.viewController = [[MainViewController alloc]init];
// if i uncomment this it crashes:
// self.window.rootViewController = self.viewController;
[self.window addSubview: viewController.view]; // Commented out if i use the rootViewController
[self.window makeKeyAndVisible];
NSLog(@"Did finish launching");
return YES;
}
I’ve tried quite some debugging methods (stacktrace does not exist, stepping through the code manually takes forever, logs are not being called before the crash), but i can’t find the problem. It crashes in libobjc.A.dylib'objc_retain:, and the only other thing in the stacktrace is objc_storeStrong. It’s not a retain/release problem (at least not directly), since i’m using ARC. The final NSLog is called and it gets out of the didFinishLaunching if i step through manually.
I can get the app working without setting the root view controller, but the whole point of redoing this part was to do everything ‘proper’ (e.g. rotation has to be done relatively hackish without the root view controller).
so StackOverflow, please tell me you have some ideas! As this is driving me crazy :S
It seems this was a stupid mistake by me, i got a rotationChanged notification too early, before i could process it. That caused a chain reaction which caused a crash in some obscure location. Thanks for the help anyway!