popViewControllerAnimated:YES crashes my app - iphone

My app crashes when I do [self.navigationController popViewControllerAnimated:YES].
It crashes more on Device than on Simulator. Please suggest how to fix this?
Date/Time: 2010-11-09 10:51:41.325 +0800
OS Version: iPhone OS 4.0.1 (8A306)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x0000286e objc_msgSend + 18
1 CoreFoundation 0x00002c30 -[NSObject(NSObject) release] + 24
2 libobjc.A.dylib 0x00003c1a objc_setProperty + 114
3 UIKit 0x000693d4 -[UINavigationController setDisappearingViewController:] + 24
4 UIKit 0x0007d5c0 -[UINavigationController _clearLastOperation] + 40
5 UIKit 0x0007d4b4 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 556
6 UIKit 0x0007d248 -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 204
7 UIKit 0x0007d0b6 -[UINavigationTransitionView _navigationTransitionDidStop] + 450
8 UIKit 0x00059974 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 184
9 UIKit 0x0005987e -[UIViewAnimationState animationDidStop:finished:] + 34
10 QuartzCore 0x000127ba run_animation_callbacks(double, void*) + 286
11 QuartzCore 0x0001265c CA::timer_callback(__CFRunLoopTimer*, void*) + 116
12 CoreFoundation 0x00071a54 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
13 CoreFoundation 0x00073ede __CFRunLoopDoTimer + 854
14 CoreFoundation 0x0007485e __CFRunLoopRun + 1082
15 CoreFoundation 0x0001d8e4 CFRunLoopRunSpecific + 224
16 CoreFoundation 0x0001d7ec CFRunLoopRunInMode + 52
17 GraphicsServices 0x000036e8 GSEventRunModal + 108
18 GraphicsServices 0x00003794 GSEventRun + 56
19 UIKit 0x000062a0 -[UIApplication _run] + 396
20 UIKit 0x00004e10 UIApplicationMain + 664
21 tenpay 0x00006124 main (main.m:13)
22 tenpay 0x00002324 start + 44

myviewcontroller = [[[MyViewController alloc]init]autorelease];
[self.navigationController pushViewController:myviewcontroller animated:YES];
[myviewcontroller release]; //This is my bug !!! I just fixed it.

This usually means you are sending a message to a released object which is a bad idea.
From the stack you can see that it is sending a release message to an object. I'd suggest that the object has already been released and thus hasa retain count of 0. Therefore a further release would be invalid.
I believe if you turn on a flag, I think it's called Zombie detection or something like that, then any message to a released object will generate a more descriptive message.
Perhaps a more experienced developer can jump in here with more details.

Yes, I believe Derek is pointing you in the right direction. Could you possibly list what kind of memory-related operations you are performing on the active controller before sending this release message (the release message is being sent implicitly when you try to pop it out). Please clarify if you are using autorelease for this controller,etc... Also it might be helpful to see what are the associated properties that you may have associated with this controller (ex: #property(nonatomic, retain, etc...)) if there are any.

Related

iPad app crashes on launch

I have an app which seems to work fine in debug mode, but now it's live in the app store it crashes every time. I have managed to find a crash log, which shows the following:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Crashed Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x3238329e __exceptionPreprocess + 158
1 libobjc.A.dylib 0x3a22e97a objc_exception_throw + 26
2 UIKit 0x3451837c +[UIStoryboard storyboardWithName:bundle:] + 436
3 UIKit 0x3435a58e -[UIApplication _loadMainStoryboardFileNamed:bundle:] + 38
4 UIKit 0x341e379c -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 524
5 UIKit 0x3418bc34 -[UIApplication handleEvent:withNewEvent:] + 1000
6 UIKit 0x3418b6c8 -[UIApplication sendEvent:] + 68
7 UIKit 0x3418b116 _UIApplicationHandleEvent + 6150
8 GraphicsServices 0x35e9659e _PurpleEventCallback + 586
9 GraphicsServices 0x35e961ce PurpleEventCallback + 30
10 CoreFoundation 0x3235816e __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 30
11 CoreFoundation 0x32358112 __CFRunLoopDoSource1 + 134
12 CoreFoundation 0x32356f94 __CFRunLoopRun + 1380
13 CoreFoundation 0x322c9eb8 CFRunLoopRunSpecific + 352
14 CoreFoundation 0x322c9d44 CFRunLoopRunInMode + 100
15 UIKit 0x341e2480 -[UIApplication _run] + 664
16 UIKit 0x341df2fc UIApplicationMain + 1116
Does anyone know what this means? I really need to submit an update for this app quickly so I need to fix it.
One great place to start is this link:
http://www.raywenderlich.com/23704/demystifying-ios-application-crash-logs
It will show you how to read your crash log.
For instance EXC_CRASH (SIGABRT) means:
The exception code is a SIGABRT. Usually, a SIGABRT exception is raised when an object receives an unimplemented message. Or to put it in simpler terms, there’s a call for a nonexistent method on an object.
This should give you a hint as to what the problem is. It's not in your code as you can see that your classes are not called in the list to the right.
I would also say that if it doesn't work in the app store you might make sure that it works for all languages on Ad-Hoc. Maybe something is missing from your storyboard?
Check the storyboard names. Make sure you have a main storyboard selected for ipad and that the name matches.

How to read this iphone app crash log

My app (named MyLittleApplication) crashes randomly when I click on a button that pops view controller.
I could use some help (to find out where should I start looking) with crash log:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x600332e0
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x351faf78 objc_msgSend + 16
1 Foundation 0x37d0a74c NSKVOPendingNotificationCreate + 216
2 Foundation 0x37d0a652 NSKeyValuePushPendingNotificationPerThread + 62
3 Foundation 0x37cfc744 NSKeyValueWillChange + 408
4 Foundation 0x37cd3848-[NSObject(NSKeyValueObserverNotification) willChangeValueForKey:] + 176
5 Foundation 0x37d55a14 _NSSetPointValueAndNotify + 76
6 UIKit 0x311f825a -[UIScrollView(Static) _adjustContentOffsetIfNecessary] + 1890
7 UIKit 0x31215a54 -[UIScrollView setFrame:] + 548
8 UIKit 0x31215802 -[UITableView setFrame:] + 182
9 POViO 0x000fcac8 0xf8000 + 19144
10 UIKit 0x31211b8e -[UIViewController _setViewAppearState:isAnimating:] + 138
11 UIKit 0x3126b8a8 -[UIViewController beginAppearanceTransition:animated:] + 184
12 UIKit 0x3121490c -[UINavigationController _startTransition:fromViewController:toViewController:] + 832
13 UIKit 0x312144fc -[UINavigationController _startDeferredTransitionIfNeeded] + 244
14 UIKit 0x3125e8e4 _popViewControllerNormal + 184
15 UIKit 0x3125e712 -[UINavigationController _popViewControllerWithTransition:allowPoppingLast:] + 386
16 UIKit 0x31242bba -[UINavigationController popToViewController:transition:] + 626
17 POViO 0x001074e6 0xf8000 + 62694
18 CoreFoundation 0x374553f6 -[NSObject performSelector:withObject:withObject:] + 46
19 UIKit 0x311eae00 -[UIApplication sendAction:to:from:forEvent:] + 56
20 UIKit 0x311eadbc -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 24
21 UIKit 0x311ead9a -[UIControl sendAction:to:forEvent:] + 38
22 UIKit 0x311eab0a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 486
23 UIKit 0x311eb442 -[UIControl touchesEnded:withEvent:] + 470
24 UIKit 0x311e9924 -[UIWindow _sendTouchesForEvent:] + 312
25 UIKit 0x311e9312 -[UIWindow sendEvent:] + 374
26 UIKit 0x311cf68e -[UIApplication sendEvent:] + 350
27 UIKit 0x311cef34 _UIApplicationHandleEvent + 5820
28 GraphicsServices 0x33c11224 PurpleEventCallback + 876
29 CoreFoundation 0x374cf51c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
30 CoreFoundation 0x374cf4be __CFRunLoopDoSource1 + 134
31 CoreFoundation 0x374ce30c __CFRunLoopRun + 1364
32 CoreFoundation 0x3745149e CFRunLoopRunSpecific + 294
33 CoreFoundation 0x37451366 CFRunLoopRunInMode + 98
34 GraphicsServices 0x33c10432 GSEventRunModal + 130
35 UIKit 0x311fdcce UIApplicationMain + 1074
36 MyLittleApplication 0x000f90ae 0xf8000 + 4270
37 MyLittleApplication 0x000f9048 0xf8000 + 4168
I suspect that it has something to do with notificationCenter and UIDeviceOrientationDidChangeNotifications I use. Is this true or am I looking in the wrong direction?
I am calling
[notificationCenter removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]
in viewDidUnload, this shuld be enough?
Can you please tell me what bug should i start looking for?
This is a stacktrace you see the stack of methods called when the crash happened.
You start at the bottom and work yourself up to the top and search for a method call from your app (the stacktrace includes calls from the frameworks too (e.g. -[UIScrollView(Static) _adjustContentOffsetIfNecessary])).
The topmost method call from your app is likely the cause of your error and you can see what the system tried afterwards.
In your case it seems that you call popToViewController and the iOS frameworks try to animate the transition from one UIViewController to the next. There seems to be a problem for the table view to set its frame and scroll to the contentOffset.
This is likely to be caused by a memory error. You get this hint by examining Exception Type: EXC_BAD_ACCESS (SIGSEGV)
EXC_BAD_ACCESS is likely a hint that you try to acces a something which is no more in the memory -> already released.
In general I would recomment to activate exveption breakpoints in Xcode:
Have you set the exception breakpoint?
got to breakpoint editor pane
click on the x in the bottom left corner
choose add exception breakpoint
Now you should see a stacktrace if an exception occurs. And Xcode should be at the line where the crash happens.
The second thing you should get familiar with is the zombie mode in Instruments.
You can find a good introduction to the zombi mode in this video.
In your case, you can see you have a EXC_BAD_ACCESS (SIGSEGV). This means you're trying to access something which isn't here, or at least was here but isn't anymore. If you can replicate the error, try using the Zombies mode of Instruments, it will tell will which thing it was expecting to access. The solution to this problem is often that you released the resource too early a resource you still need.
You might want to throw some NSLog statements in the methods just so you can have an idea of where things are going wrong. Sometimes those iOS messages can be a little cryptic.

iPhone app crash with unknown error

I am developing an application to take photos and upload the photos to remote server.
I have customized camera view using overlay view. App allows to take more than 1 photos per time and photos will be saved to device just after taking photos. When I am taking photos app gives memory warning and then crash. Followings are the from crash report. I have talked with Apple support team and they said this is not due to memory issue. This is because of trying to send an action to one of your controller object that no longer exists.
OS Version: iPhone OS 4.3.3 (8J2)
Report Version: 104
Exception Type: EXC_BAD_ACCESS
(SIGSEGV) Exception Codes:
KERN_INVALID_ADDRESS at 0x73980000
Crashed Thread: 0
Thread 0 name: Dispatch queue:
com.apple.main-thread Thread 0
Crashed: 0 libobjc.A.dylib
0x34499c9a objc_msgSend + 18 1
UIKit
0x30a8bc1a
-[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 86 2 CoreFoundation
0x308f056a -[NSObject(NSObject)
performSelector:withObject:withObject:]
+ 18 3 UIKit 0x309feec2 -[UIApplication
sendAction:to:from:forEvent:] + 78 4
UIKit
0x309fee62 -[UIApplication
sendAction:toTarget:fromSender:forEvent:]
+ 26 5 UIKit 0x309fee34 -[UIControl
sendAction:to:forEvent:] + 32 6
UIKit
0x309feb86 -[UIControl(Internal)
_sendActionsForEvents:withEvent:] + 350 7 UIKit
0x309ff41c -[UIControl
touchesEnded:withEvent:] + 336 8
UIKit
0x309e452e
_UIGestureRecognizerSortAndSendDelayedTouches
+ 2194 9 UIKit 0x309e3bfa
_UIGestureRecognizerUpdateObserver + 690 10 CoreFoundation
0x30957a2e
CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
+ 10 11 CoreFoundation 0x3095945e __CFRunLoopDoObservers +
406 12 CoreFoundation
0x3095a754 __CFRunLoopRun + 848 13
CoreFoundation
0x308eaebc CFRunLoopRunSpecific + 224
14 CoreFoundation
0x308eadc4 CFRunLoopRunInMode + 52 15
GraphicsServices
0x30269418 GSEventRunModal + 108 16
GraphicsServices
0x302694c4 GSEventRun + 56 17 UIKit
0x30a10d62 -[UIApplication _run] +
398 18 UIKit
0x30a0e800 UIApplicationMain + 664 19
hand-e-pix
0x000025a4 main (main.m:14) 20
hand-e-pix
0x0000254c start + 32
Can anyone please help me to identify what cause this problem?
Many Thanks
Regards
Chin
This could easily be related to a retain/release issue. Make sure you balance your reetain/release calls. Also make sure you do not reference any deallocated objects in your code.
You might want to take a look at enabling NSZombieEnabled in order to track this one down.
You can find information about how to enable it here.

unrecognized selector sent to instance. Method being called for random objects

Ok, so this has me completely stumped just like the guy here with the exact problem.
I have a UITableView with some rows in a view controller which supports autorotation and sometimes, if i rotate the phone, i get "EXC_BAD_ACCESS" and sometimes i get SIGABRT with a stack trace like:
2010-11-19 16:51:05.634 [2306:307] -[CABasicAnimation numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x58207d0
2010-11-19 16:51:05.688 [2306:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CABasicAnimation numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x58207d0'
*** Call stack at first throw:
(
0 CoreFoundation 0x344aaed3 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x33975811 objc_exception_throw + 24
2 CoreFoundation 0x344ac683 -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x344541d9 ___forwarding___ + 508
4 CoreFoundation 0x34453f90 _CF_forwarding_prep_0 + 48
5 UIKit 0x31b20717 -[UITableViewRowData(UITableViewRowDataPrivate) _updateNumSections] + 66
6 UIKit 0x31b20677 -[UITableViewRowData invalidateAllSections] + 50
7 UIKit 0x31b2048d -[UITableView(_UITableViewPrivate) _updateRowData] + 64
8 UIKit 0x31b22941 -[UITableView(_UITableViewPrivate) _ensureRowDataIsLoaded] + 24
9 UIKit 0x31b22909 -[UITableView numberOfSections] + 16
10 UIKit 0x31bd114f -[UISearchDisplayController _updateNoSearchResultsMessageVisiblity] + 54
11 UIKit 0x31cfbef7 -[UISearchDisplayController windowWillAnimateRotation:] + 478
12 Foundation 0x3325d6b3 _nsnote_callback + 142
13 CoreFoundation 0x34431713 __CFXNotificationPost_old + 402
14 CoreFoundation 0x344313b3 _CFXNotificationPostNotification + 118
15 Foundation 0x3324cdb7 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
16 UIKit 0x31b5dbb7 -[UIWindow _setRotatableClient:toOrientation:duration:force:] + 3114
17 UIKit 0x31b64013 -[UIWindow _setRotatableViewOrientation:duration:force:] + 50
18 UIKit 0x31b39a0f -[UIWindow _updateToInterfaceOrientation:duration:force:] + 74
19 UIKit 0x31b39be9 -[UIWindow _updateInterfaceOrientationFromDeviceOrientation:] + 112
20 UIKit 0x31b39b15 -[UIWindow _handleDeviceOrientationChange:] + 88
21 Foundation 0x3325d6b3 _nsnote_callback + 142
22 CoreFoundation 0x34431713 __CFXNotificationPost_old + 402
23 CoreFoundation 0x344313b3 _CFXNotificationPostNotification + 118
24 Foundation 0x3324cdb7 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
25 UIKit 0x31b0d0ed -[UIDevice setOrientation:animated:] + 144
26 UIKit 0x31b2a51b -[UIApplication handleEvent:withNewEvent:] + 2738
27 UIKit 0x31b29901 -[UIApplication sendEvent:] + 44
28 UIKit 0x31b29337 _UIApplicationHandleEvent + 5110
29 GraphicsServices 0x3026c04b PurpleEventCallback + 666
30 CoreFoundation 0x3443fce3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
31 CoreFoundation 0x3443fca7 __CFRunLoopDoSource1 + 166
32 CoreFoundation 0x3443256d __CFRunLoopRun + 520
33 CoreFoundation 0x34432277 CFRunLoopRunSpecific + 230
34 CoreFoundation 0x3443217f CFRunLoopRunInMode + 58
35 GraphicsServices 0x3026b5f3 GSEventRunModal + 114
36 GraphicsServices 0x3026b69f GSEventRun + 62
37 UIKit 0x31ad0123 -[UIApplication _run] + 402
38 UIKit 0x31ace12f UIApplicationMain + 670
39 App 0x0000285f main + 70
40 App 0x00002814 start + 40
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
In this case it is CABasicAnimation on which numberOfSectionsInTableView is being called but sometimes there are class names like NSMachPort which i have never heard of. Also, the method being called numberOfSectionsInTableView remains the same with the class names changing to always give a doesNotRecognizeSelector exception.
Also this problem only happens when i try to rotate the device. Whenever i get a stack trace like above, there are all system functions which makes it difficult to debug.
Really need some expert advice on this. Please read the forum mentioned above to be clear about the issue.
Whoa! I thought i knew NSZombies enough but i was wrong!
I enabled NSZombies which led me to:
*** -[ContactsViewController numberOfSectionsInTableView:]: message sent to deallocated instance 0x88dafa0
Doing "po 0x88dafa0" wont work because that object's memory was already freed.
Some more Googling led me to this where the author describes how to find freed/deallocated objects. We just have to set MallocStackLoggingNoCompact to 1 in the Variables to be set in the environment along with NSZombieEnabled.
The output i got with the info malloc-history 0xf270740 command had a line:
-[VoicePlayController actionSheet:clickedButtonAtIndex:] at /Users/Documents/Xcode Projects/Classes/VoicePlayController.m:454
The code on that line is:
contactsViewController = [[ContactsViewController alloc] initWithNibName:#"ContactsViewController" bundle:nil];
I moved the [contactsViewController release]; line to dealloc method instead of immediately after [self.navigationController presentModalViewController:contactsViewController animated:YES]; and the problem is gone!
Start with enabling NSZombies. What it sounds like is you are over-releasing an object.

App Crashing in NSURLConnection

I am trying to figure out what is causing this crash. I have built and given the app to our testers but we cannot seem to reproduce this reliably. It just happens sometimes...
Thread 0 Crashed:
0 libobjc.A.dylib 0x000027da objc_msgSend + 18
1 Foundation 0x00032896 -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] + 62
2 Foundation 0x00032818 _NSURLConnectionDidFinishLoading + 72
3 CFNetwork 0x00010dd8 URLConnectionClient::_clientDidFinishLoading(URLConnectionClient::ClientConnectionEventQueue*) + 160
4 CFNetwork 0x00004ad4 URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XClientEvent, XClientEventParams>*, long) + 96
5 CFNetwork 0x000049c4 URLConnectionClient::processEvents() + 64
6 CFNetwork 0x00004976 URLConnection::multiplexerClientPerform(RunLoopMultiplexer*) + 30
7 CFNetwork 0x000048f4 MultiplexerSource::perform() + 120
8 CFNetwork 0x00004872 MultiplexerSource::_perform(void*) + 2
9 CoreFoundation 0x00055f1e __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
10 CoreFoundation 0x00027ba0 __CFRunLoopDoSources0 + 376
11 CoreFoundation 0x00027444 __CFRunLoopRun + 224
12 CoreFoundation 0x00027270 CFRunLoopRunSpecific + 224
13 CoreFoundation 0x00027178 CFRunLoopRunInMode + 52
14 GraphicsServices 0x000045ec GSEventRunModal + 108
15 GraphicsServices 0x00004698 GSEventRun + 56
16 UIKit 0x0000411c -[UIApplication _run] + 396
17 UIKit 0x00002128 UIApplicationMain + 664
18 myapp 0x000020d8 main (main.m:14)
19 myapp 0x0000208c start + 32
Any advice would be greatly appreciated. The app is built in XCode 3.2.4 using SDK 4.1.
Cheers...
I would try turning on NSZombieEnabled and see if that sheds any light on the issue. Is the delegate for the connection still around and valid?
Ben has some sound advice. Turn NSZombieEnabled to on.
I can tell you with almost 100% certainty that it is crashing because you have a nil object when the delegate is attempting to send it a message.
The fact that it is only crashing sometimes, tells me that you are probably using autorelease. Autorelease never decrements the retain count at exactly the same time, so sometimes your object will still be alive when it gets a delegate message and the app works. However, sometimes that object will have been released and the app crashes.