App crashing without errors - objective-c

In my app, I have four buttons. When I press two of the four buttons, the app freezes. The weird thing is that no errors appear and there is nothing in the debugger window. I am new to iOS development, so I have no idea how to fix this. The app worked fine before the app started crashing, and I didn't alter any code, so I don't know what is going on. Can someone help me out?
Here is the code for where the button is pushed. It has been working fine, so I don't know why it doesn't work all of the sudden:
- (IBAction)showMapView:(id)sender
{
P2OViewController *pvc = [[P2OViewController alloc]init];
[self.navigationController pushViewController:pvc
animated:YES];
}
- (IBAction)showTableView:(id)sender
{
TableViewController *tableView = [[TableViewController alloc]init];
[self.navigationController pushViewController:tableView
animated:YES];
}
So I added global breakpoints, and nothing is happening. The app is still running, and the debugger navigator says it is still running. So I guess the app is freezing, and not crashing. I have no idea how to fix this.

Seems like a memory problem.Instead of creating a p20viewcontroller object and tableviewcontroller object on every button click,try creating these objects only once somewhere in the start of the program.
the button click should only contain the code to navigate to the next screen.Not creating a new object on every button click.

I'd suggest you check the connections between your IBActions and your code. Unexplained errors like this can be caused by missing or incorrect connections in IB.

Related

Chromium tabs – can't update tab icon

I'm trying out chromium-tabs. I have an issue where the icon of a tab never gets properly updated after it gets created for the first time. In my CTTabContents subclass, I have:
- (void)tabDidBecomeSelected {
NSLog(#"selected");
[self setIcon:[NSImage imageNamed:#"default"]];
}
- (void)tabDidResignSelected {
NSLog(#"resign selected");
[self setIcon:[NSImage imageNamed:#"notification"]];
}
This should change the icon if the tab resigns its selected status to a different one. But it doesn't. The icon never changes. Note that I've tried the same exact calls in (id)initWithBaseTabContents:(CTTabContents *)baseContents andJid:(NSString *)jid andStatus:(NSString *)status where they work fine, so the calls fail only on an update of the icon later.
I've also made sure the functions are getting called (I see the log statements). What's the problem here? Also, is this the fork that Chrome actually uses? It obviously works in Chrome, which is strange... Am I doing something wrong?
I even tried doing [[[self.browser.windowController window] contentView] setNeedsDisplay:YES]; in the tabDidBecomeSelected functions, to force the whole window to redraw, in case their code for updating the icon fails, but still no luck.

Setting window root viewcontroller Bad access without stack trace

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
You don't need to do this:
[self.window addSubview: viewController.view];
When you set the view controller as root view controller, it's view already becomes subview of the window.
EDIT
However this wouldn't cause any problem.
Maybe the problem isn't in the code. Sometimes my apps crash too, and I get mad. Usually this happens because I drag the project from another folder and xcode finds troubles with permissions, or for some other (to me) unknown reasons.
Try to clean the project with alt+cmd+k . If that doesn't work you might have problems with permissions. So create another project and copy all the files you wrote to it.
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!

presentViewController: crash on iOS <6 (AutoLayout)

This is a weird crash I am getting. The crash happens when I press a button that goes to a certain ViewController. The line which it crashes on is:
DestinationInformationViewController *info = [[DestinationInformationViewController alloc] init];
[info setModalTransitionStyle: UIModalTransitionStyleCrossDissolve];
[self presentViewController:info animated:YES completion: nil]; // CRASHES HERE
[info release];
The crash trace is:
*** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named NSLayoutConstraint'
*** First throw call stack:
(0x3758288f 0x35287259 0x37582789 0x375827ab 0x3153d54d 0x3153d6bb 0x3153d423 0x314ce001 0x3143c3c7 0x31319c59 0x3128fc17 0x3129a267 0x3129a1d5 0x3133959b 0x31338367 0x84091 0x374dc3fd 0x31271e07 0x31271dc3 0x31271da1 0x31271b11 0x31272449 0x3127092b 0x31270319 0x31256695 0x31255f3b 0x33c9822b 0x37556523 0x375564c5 0x37555313 0x374d84a5 0x374d836d 0x33c97439 0x31284cd5 0x82bb3 0x71200)
terminate called throwing an exception(gdb) Could not instantiate class named NSLayoutConstraint
NOTE: This crashes on my iPhone 4 iOS 5.1 but not on my iPhone 4S iOS 6 Beta 2
I believe this is an issue with Xcode's new interface builder. Did you happen to build your .xib using Xcode 4.5's interface builder? I've run into this same problem just now, and I think that's the problem. My app runs on iOS 6, but not anything older.
And you need to make sure you turn off Use Auto Layout for your xibs.
That can be done by:
Open your xib.
Go to the File Inspector tab.
Find the Interface Builder Document section on the right toolbar.
Uncheck the Use Auto Layout option.
I had the same problem when I downloaded new XCode update and IOS6 SDK. Here's how I solved it:
Select the Interface builder file (whether xib or storyboard file) where your error occurs.
In assistant editor on the right in XCode, select the first tab from the left, and there is a checkbox for option "Use Autolayout" like on the screenshot above.
Uncheck the checkbox.
Nagaraja asks "How to resolve the same if we are not using xib? I ran into exactly this problem. I created a controller with a xib, and then I decided to remove the xib file. The crash did not go away. The problem was that I needed to implement
- (void) loadView
in my controller class. Once I implemented this method the problem got solved.
Another possible reason for a crash with presentViewController is having something in the nib connected to a variable that is no longer there - the variable either having it's name changed or it was deleted.

Application crashes while logging out in iPAD

My question is specific to iPAD, and I also aware of the basic memory management of iOS, but I am having a different problem.
As I have build an application where I have several UIViewControllers and UIViews,
I have a loginController thats gets called when I launch the App.
My MainView is a single screen with all the ViewController loaded and placed at their respective places and the app runs fine and smoothly.
Problem:
Problem comes when I logout, most of the time my App crashes by saying EXC_BAD on the
[super dealloc] line of my mainView controller.
As for now on I have added a custom function cleanUP in all my viewControllers that gets called when user logout from the app.
Is this the right approach ?
As I know that we can clean up in our didload etc. function and the dealloc gets called too.
but here i have an iPAD when my all viewControllers are just open in front of me, They will be closed or not visible when I logout from the App.
So how to approach on my crash issue and How to manage memory here in my iPAD?
The best way I know to resolve bad-access problems is to use Instruments with the Zombie tool. As you probably know, when you get a bad access issue, is because you try to access to an object that is deallocated.
Try go to Product -> Profile and choose Zombie. Hit record and reproduce your crash. then inspect the pointer to the object that produced that crash and look for the retain count.

Facebook Connect Login Dialog crashing app

Of the many problems I've been having with my current app, this is one of the most annoying.
In the simulator the login dialog works fine, however on a device it's just a frozen white box and the console prints the following:
void SendDelegateMessage(NSInvocation*): delegate
(webView:resource:willSendRequest:redirectResponse:fromDataSource:)
failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode
I've looked this up but I'm still not sure what it means.
If I try switching
[self authorizeWithFBAppAuth:NO safariAuth:NO];
to
[self authorizeWithFBAppAuth:NO safariAuth:YES];
it switches to the safari app to verify but this somehow kills my app with an error which says ReturnNotPermittedKillClient.
Has anyone experienced a similar problem? On my last app it just worked without any of these issues, and as far as I can see I've done everything the same way this time. However this project was inherited from someone else so there may be underlying causes that I am not aware of.
Edit: Just tried moving the login request from didFinishLaunchingWithOptions to a point in the intro screen class where everything else has already been loaded, just in case it was a memory issue caused by too many tasks trying to run at the same time. This time the error message didn't appear, however the login box still remained white and then closed the app a few seconds later.
Edit2: Seems like it's simply a memory error. I changed all variables which I had previously released to be retained, which has fixed the problem on my 3GS. However on my iPad 1 the problem persists. Incidentally, when changing shouldAutorotateToInterfaceOrientation from using landscaperight to using landscaperight or landscapeleft, when I rotate the iPad I get a memory warning and then the same crash. In both cases there are no debug error messages other than the memory warning, and the app just closes down - there is no breakpoint etc to see where the issue lies.
if you are using the webview then we need to do this first b4 moving to next view .delegate = nil;
This might be what you want:
There are other branches of this in NSObject in the documentation.
Code:
[self performSelector: withObject: afterDelay: ]
The problem was simply down to memory. After changing the way it loads images, sounds etc the problem has gone away.