Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 13, 2011, 07:10 AM   #1
SimonBS
macrumors regular
 
Join Date: Dec 2009
Application crashes with EXC_BAD_ACCESS

Hi,

I have an application which used top bar navigation and a MapView. On the map view I have placed some annotations and when selecting an annotation, pressing the disclosure button to go into a subview and then going back to the MapView using the back button my application crashes.
When running it in debug mode I get the message "EXC_BAD_ACCESS" in the console but I don't know why I get this error and where I should look to correct it.

Can anyone help me figure out why my application keeps crashing?

I have made a short video showing my crash (because I'm afraid that I do not explain it very well)

The video can be seen on this link http://snuzzer.dk/pub/iPhoneAppMapKitCrash.mov

Please tell me if you need to see any code in order to determine the reason for the crash. I am not sure what code would be necessary to show as I don't know where to look.

This is the output of my stack trace but using that I still can't figure out why my application crashes.
Code:
#0  0x01275a63 in objc_msgSend
#1  0x0586c860 in ??
#2  0x0037ef1d in -[UINavigationController setDisappearingViewController:]
#3  0x0037c4f6 in -[UINavigationController _clearLastOperation]
#4  0x0037ce3f in -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
#5  0x00509e23 in -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:]
#6  0x0050afd2 in -[UINavigationTransitionView _cleanupTransition]
#7  0x002f6665 in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
#8  0x002f64f7 in -[UIViewAnimationState animationDidStop:finished:]
#9  0x01ffa6cb in run_animation_callbacks
#10 0x01ffa589 in CA::timer_callback
#11 0x010f4fe3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
#12 0x010f6594 in __CFRunLoopDoTimer
#13 0x01052cc9 in __CFRunLoopRun
#14 0x01052240 in CFRunLoopRunSpecific
#15 0x01052161 in CFRunLoopRunInMode
#16 0x01a48268 in GSEventRunModal
#17 0x01a4832d in GSEventRun
#18 0x002d442e in UIApplicationMain
#19 0x00002918 in main at main.m:14
__________________
SimonBS is offline   0 Reply With Quote
Old Feb 13, 2011, 10:10 AM   #2
cnstoll
macrumors regular
 
Join Date: Aug 2010
So, are you actually calling setDisappearingViewController on an instance of UINavigationController?

Code:
-[UINavigationController setDisappearingViewController:]
To the best of my knowledge, that method doesn't exist. So that right there would be your problem. Post any code related to that method call.
cnstoll is offline   0 Reply With Quote
Old Feb 13, 2011, 10:22 AM   #3
SimonBS
Thread Starter
macrumors regular
 
Join Date: Dec 2009
Quote:
Originally Posted by cnstoll View Post
So, are you actually calling setDisappearingViewController on an instance of UINavigationController?

Code:
-[UINavigationController setDisappearingViewController:]
To the best of my knowledge, that method doesn't exist. So that right there would be your problem. Post any code related to that method call.
I just did a search for "setDisappear" in my project and I do not have that line of code anywhere in my code
__________________
SimonBS is offline   0 Reply With Quote
Old Feb 13, 2011, 10:23 AM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
It's almost certainly an internal method being called by the navigation controller. Normally this sort of bug is due to you releasing an object early (or failing to retain an object you should retain).
robbieduncan is offline   0 Reply With Quote
Old Feb 13, 2011, 10:30 AM   #5
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
A crash in objc_msgSend is due to sending a message to an object that's already been dealloced. If you run with NSZombies enabled you can usually find out what the object it.
PhoneyDeveloper is offline   0 Reply With Quote
Old Feb 13, 2011, 10:37 AM   #6
SimonBS
Thread Starter
macrumors regular
 
Join Date: Dec 2009
Quote:
Originally Posted by robbieduncan View Post
It's almost certainly an internal method being called by the navigation controller. Normally this sort of bug is due to you releasing an object early (or failing to retain an object you should retain).
Based on this information I tried to play around with my releases in MapViewController.m (as the name indicates - this file controls my MapView) and it seems that when I do not release my annotationDetailViewController (the viewController which changes the view when the disclosure button is tapped) I can't reproduce the error.

My code looks like this:

Code:
 - (void)mapView:(MKMapView *)aMapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
	for(MyAnnotation* a in mapView.annotations) { // searching for chosen annotation
		if(view.annotation == a) {
			// set array from plist
			NSString *path = [[NSBundle mainBundle] pathForResource:@"Annotations" ofType:@"plist"];
			NSMutableArray* anns = [[NSMutableArray alloc] initWithContentsOfFile:path];

			AnnotationDetailViewController *annotationDetailViewController = [[AnnotationDetailViewController alloc] initWithNibName:@"AnnotationDetailViewController" bundle:nil];
			annotationDetailViewController.ann = [anns objectAtIndex:[a.annId intValue]];
			
			[self.navigationController pushViewController:annotationDetailViewController animated:YES];
			[annotationDetailViewController release];
			[anns release];
		}
	}
}
When I remove [annotationDetailViewController release]; it does not seem to crash. Does this sound right and if so, can anyone tell me why this could be right and when I would release it then? I will keep playing with the app to see if I can reproduce the error.

Quote:
Originally Posted by PhoneyDeveloper View Post
A crash in objc_msgSend is due to sending a message to an object that's already been dealloced. If you run with NSZombies enabled you can usually find out what the object it.
I read about NSZombies somewhere on the internet and found out how to enable the zombies but not how to use them to find the object that might cause the error. Can you please explain this to me? I simply couldn't find the place to look.
__________________

Last edited by SimonBS; Feb 13, 2011 at 11:29 AM. Reason: Corrected stupid typos
SimonBS is offline   0 Reply With Quote
Old Feb 13, 2011, 11:55 AM   #7
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
The code you show is correct WITH the release. Obviously the memory error is being hidden when you don't release the view controller. In effect you're trading a memory leak for a memory error.

When you enable NSZombies you should then run the app. If an error occurs where the code messages a dealloced object there will be an error message printed that gives more detail about the object that's been messaged. This will help you to determine what the error is.

Most likely the object that's being dealloced prematurely is an ivar of the view controller or is a view in the view hierarchy of that view controller.
PhoneyDeveloper is offline   0 Reply With Quote
Old Feb 13, 2011, 12:30 PM   #8
SimonBS
Thread Starter
macrumors regular
 
Join Date: Dec 2009
Quote:
Originally Posted by PhoneyDeveloper View Post
The code you show is correct WITH the release. Obviously the memory error is being hidden when you don't release the view controller. In effect you're trading a memory leak for a memory error.
That's exactly what I was afraid of

Quote:
Originally Posted by PhoneyDeveloper View Post
When you enable NSZombies you should then run the app. If an error occurs where the code messages a dealloced object there will be an error message printed that gives more detail about the object that's been messaged. This will help you to determine what the error is.
When NSZombieEnabled is set to 'YES' I do not get any error. The app 'just works' but no error is printed.

Quote:
Originally Posted by PhoneyDeveloper View Post
Most likely the object that's being dealloced prematurely is an ivar of the view controller or is a view in the view hierarchy of that view controller.
I am not sure what this means Knowing that the error does not occur when annotationDetailViewController is not released, do you have an idea where the error might be?
__________________
SimonBS is offline   0 Reply With Quote
Old Feb 13, 2011, 02:34 PM   #9
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
My comment on where the error might be is only a guess. Have you run build and analyze?

Does the app get memory warnings when the view controller is covered by the map view? It's possible that your code isn't handling memory warnings correctly.
PhoneyDeveloper is offline   0 Reply With Quote
Old Feb 13, 2011, 02:57 PM   #10
SimonBS
Thread Starter
macrumors regular
 
Join Date: Dec 2009
Quote:
Originally Posted by PhoneyDeveloper View Post
My comment on where the error might be is only a guess. Have you run build and analyze?

Does the app get memory warnings when the view controller is covered by the map view? It's possible that your code isn't handling memory warnings correctly.
When running Build and Analyze, I get no errors. I got some earlier today but fixed them.

The app dos not seem to get any other memory warnings (or are there any particular tools to test this?)
__________________
SimonBS is offline   0 Reply With Quote
Old Feb 13, 2011, 03:15 PM   #11
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
When your app gets a memory warning a brief message is written to the debugger console. I also have some NSLogs in the relevant methods in my view controllers and the app delegate so I can see it when it happens.

Does the bug only happen on the device?
PhoneyDeveloper is offline   0 Reply With Quote
Old Feb 13, 2011, 03:17 PM   #12
SimonBS
Thread Starter
macrumors regular
 
Join Date: Dec 2009
Quote:
Originally Posted by PhoneyDeveloper View Post
When your app gets a memory warning a brief message is written to the debugger console. I also have some NSLogs in the relevant methods in my view controllers and the app delegate so I can see it when it happens.

Does the bug only happen on the device?
It happens in the simulator. I have not tested it on the device yet as I am waiting for Apple to approve my developer license information
__________________
SimonBS is offline   0 Reply With Quote
Old Feb 13, 2011, 04:20 PM   #13
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
OK, if you're only running on the Sim then it's not related to memory warnings.
PhoneyDeveloper is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Tags
crash, exc_bad_access, iphone, sdk

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: EXC_BAD_ACCESS problem larswik iPhone/iPad Programming 0 Jan 27, 2014 08:33 PM
iPad: iPad Crashes to safe mode right after you delete/uninstall an application Molavydez Jailbreaks and iOS Hacks 2 Mar 5, 2013 04:09 PM
Please Help: EXC_BAD_ACCESS error stevegreen22 Mac Programming 4 Nov 19, 2012 06:16 PM
Notes Application Crashes yodayoda OS X 10.8 Mountain Lion 8 Aug 1, 2012 10:19 AM
Getting crazy also with EXC_BAD_ACCESS jivaro Mac Programming 5 Jun 1, 2012 08:49 PM

Forum Jump

All times are GMT -5. The time now is 09:16 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC