I'm seeing a strange crash in one of my apps that seems to be coming from a private method on UIAlertView. I've down some searching and found a few other references to this method being involved in crashes such as here, but I'm not convinced that the cause is the same. However to be certain made sure that I always set the UIAlertView delegate to nil whenever the delegate is deallocated.
The stack trace is as follows:
Exception Type: SIGABRT
Exception Codes: #0 at 0x351ce32c
Crashed Thread: 0
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x351ce32c __pthread_kill + 8
1 libsystem_c.dylib 0x370c329f abort + 95
2 eLogbook 0x000bbacd -[GetOperationPartsDictionary init] (GetOperationPartsDictionary.m:22)
3 UIKit 0x32557f93 -[UIAlertView(Private) _popoutAnimationDidStop:finished:] + 855
4 UIKit 0x3240dc53 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 471
5 UIKit 0x3241357d -[UIViewAnimationState animationDidStop:finished:] + 53
6 QuartzCore 0x36eeac2f CA::Layer::run_animation_callbacks(void*) + 203
7 libdispatch.dylib 0x3140ae91 _dispatch_main_queue_callback_4CF$VARIANT$up + 197
8 CoreFoundation 0x353ad2ad __CFRunLoopRun + 1269
9 CoreFoundation 0x353304a5 CFRunLoopRunSpecific + 301
10 CoreFoundation 0x3533036d CFRunLoopRunInMode + 105
11 GraphicsServices 0x3662c439 GSEventRunModal + 137
12 UIKit 0x32426e7d UIApplicationMain + 1081
13 eLogbook 0x0007767f main (main.m:14)
The thing that is really confusing me about this is that the -[UIAlertView(Private) _popoutAnimationDidStop:finished:] method appears to be calling the init method on my GetOperationPartsDictionary class. From the limited amount of information I've had from users this crash is happening on startup, at which point that class would not have been loaded.
I'm using QuincyKit to deliver the crash reports to a server, from there they're symbolicated using the standard symbolicatecrash script. The version of Xcode being used to symbolicate the crash is the same version that was used to build the binary, and I'm confident that the dSYM used to symbolicate the crash is the correct one - the line numbers for my code are correct for example.
Anyone have any thoughts on this?
Edit: should have added that this is occurring in the field with a live app, but only occasionally. It has affected maybe 1 or 2 users in a thousand or so, but I have never been able to reproduce it either on a device or in the simulator.
Looks like you have called the UIAlertViewDelegate after the alertview has been released.
Release it only in the dealloc method like this :
-(void)dealloc {
self.alertView.delegate = nil; //setting delegate to nil
self.alertView = nil; //if you have defined alert as property
//other release statements of your controller
[super dealloc];
}
Related
I have a little CLT for copying and pasting images, written in Objective-C++. Until recently, this program compiled and ran as intended – but only just now, it seems, it has started crashing in the call to [NSApplication sharedApplication].
The stack traces indicate that the crash happens when NSApplication initializes an NSUserDefaults instance, which ends up calling a CFDictionary-related function (i.e. CFDictionarySetValue) which then crashes in free… but from within libjemalloc.
Here’s an example stack trace:
- Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libjemalloc.2.dylib 0x000000010e7b4ec5 free + 164
1 libjemalloc.2.dylib 0x000000010e7e3d50 zone_free + 168
2 com.apple.CoreFoundation 0x00007fffc5a912c5 __CFBasicHashRehash + 3461
3 com.apple.CoreFoundation 0x00007fffc5a96927 __CFBasicHashAddValue + 103
4 com.apple.CoreFoundation 0x00007fffc5a97a3d CFDictionarySetValue + 221
5 com.apple.CoreFoundation 0x00007fffc5c467da __63-[_CFXPreferences(SearchListAdditions) withSnapshotSearchList:]_block_invoke + 554
6 com.apple.CoreFoundation 0x00007fffc5c4710f -[_CFXPreferences(SearchListAdditions) withSearchLists:] + 79
7 com.apple.CoreFoundation 0x00007fffc5c4655b -[_CFXPreferences(SearchListAdditions) withSnapshotSearchList:] + 155
8 com.apple.CoreFoundation 0x00007fffc5ad08bb __CFXPreferencesCopyCurrentApplicationState + 123
9 com.apple.CoreFoundation 0x00007fffc5ad04dc _CFLocaleCopyCurrentGuts + 268
10 com.apple.CoreFoundation 0x00007fffc5ad0399 +[NSLocale currentLocale] + 9
11 com.apple.Foundation 0x00007fffc7508026 -[NSUserDefaults(NSUserDefaults) init] + 1589
12 com.apple.Foundation 0x00007fffc7507995 +[NSUserDefaults(NSUserDefaults) standardUserDefaults] + 81
13 com.apple.AppKit 0x00007fffc35c9254 +[NSApplication initialize] + 90
14 libobjc.A.dylib 0x00007fffda9b0b04 CALLING_SOME_+initialize_METHOD + 19
15 libobjc.A.dylib 0x00007fffda9a16b9 _class_initialize + 579
16 libobjc.A.dylib 0x00007fffda9a105b lookUpImpOrForward + 240
17 libobjc.A.dylib 0x00007fffda9a0ad4 _objc_msgSend_uncached + 68
18 impaste 0x0000000106197198 void objc::run_thread<AXDryRunThread>(NSDictionary*) + 120
19 impaste 0x0000000106196820 main + 2608
20 libdyld.dylib 0x00007fffdb294235 start + 1
… This last bit is most curious as I am not using the JeMalloc library. Neither my CLT program nor the libraries on which it is built have anything to do with JeMalloc, and the build system doesn’t currently reference it at all. I don’t include anything from, or link anything to, the JeMalloc library at any point whatsoever.
However: from the stack trace, it looks like the CoreFoundation libraries I am using are, in fact, using JeMalloc.
I don’t know much about JeMalloc, but I do believe that it provides a global drop-in replacement for malloc and free (in addition to furnishing a host of custom, fine-grained memory-management functions).
My call to [NSApplication sharedApplication] (as seen on line #18 of the stack trace above) looks like this:
template <typename OCThreadType> inline
void run_thread(NSDictionary* options = #{}) {
#autoreleasepool {
[NSApplication sharedApplication];
[[[OCThreadType alloc] initWithOptions:options] start];
AXAppDelegate* delegate = [[AXAppDelegate alloc] init];
NSApp.delegate = delegate;
[NSApp run];
};
}
Can anyone shed some light on this? What could cause this program to crash in this fashion (and specifically, what may have changed recently in CoreFoundation)?
My app works great when I build and debug but when I run on its own, it crashes due to some other issues.
I have one NSObject class, one UITableView class, one UIView class , one UITableViewCell class and one NSOperation class.
Does any body have similar issues or if any one can help me out.
Application Specific Information:
objc_msgSend() selector name: release
iPhone Simulator 235, iPhone OS 4.2 (iPhone/8C134)
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x01134a67 objc_msgSend + 27
1 UIKit 0x004ab1e2 -[UITableViewCell removeFromSuperview] + 167
2 UIKit 0x003249d9 -[UIView dealloc] + 340
3 UIKit 0x0032e281 -[UIScrollView dealloc] + 341
4 UIKit 0x003661ce -[UITableView dealloc] + 1085
5 Foundation 0x000698da __delayedPerformCleanup + 59
6 CoreFoundation 0x00f4bbde CFRunLoopTimerInvalidate + 446
7 CoreFoundation 0x00fb57d7 __CFRunLoopDoTimer + 1799
8 CoreFoundation 0x00f11cc9 __CFRunLoopRun + 1817
9 CoreFoundation 0x00f11240 CFRunLoopRunSpecific + 208
10 CoreFoundation 0x00f11161 CFRunLoopRunInMode + 97
11 GraphicsServices 0x01874268 GSEventRunModal + 217
12 GraphicsServices 0x0187432d GSEventRun + 115
13 UIKit 0x002fa42e UIApplicationMain + 1160
14 Time 0x00001e08 main + 102 (main.m:14)
15 Time 0x00001d99 start + 53
This technote has the technical info on crashlogs:
http://developer.apple.com/library/mac/#technotes/tn2004/tn2123.html
However, you are having a debugging problem, not a crashlog problem.
See tips for debugging here:
http://www.cocoadev.com/index.pl?DebuggingTechniques
Interpreting crash logs takes practice. People here see this: removeFromSuperview and immediately think "Aha, a clue! this is likely a memory issue" because removeFromSuperview will remove a view then decrement it's retain count. if the retain count is already zero, then decrementing one more time may lead to a crash. Thus, they think you are over releasing your UITableViewCell
check your UITableViewCell for alloc/init, release or autorelease...
Been hunting down an intermittent crash in my app. Finally unlocked the secrets to symbolocating my crash report, and this is what I found:
Incident Identifier: BFCE991E-5F9C-4F04-89AD-A0060EDE73D1
CrashReporter Key: 263d1a93e7ce2d75b397b6ef42b1bc4f29d22f9d
Hardware Model: iPhone2,1
Process: Wine Brain [2787]
Path: /var/mobile/Applications/197DA851-3F8A-486E-8675-74B521A1FD72/Wine Brain.app/Wine Brain
Identifier: Wine Brain
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2010-12-26 19:21:21.551 -0500
OS Version: iPhone OS 4.2.1 (8C148a)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000d
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x3199f464 objc_msgSend + 16
1 Wine Brain 0x0000a0b4 0x1000 + 37044
2 CoreFoundation 0x31436f74 -[NSObject(NSObject) release] + 24
3 libobjc.A.dylib 0x319a0812 objc_setProperty + 114
4 UIKit 0x338f74a0 -[UINavigationController setDisappearingViewController:] + 24
5 UIKit 0x338f7478 -[UINavigationController _clearLastOperation] + 40
6 UIKit 0x338f7394 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 556
7 UIKit 0x338f7128 -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 204
8 UIKit 0x338f6dee -[UINavigationTransitionView _cleanupTransition] + 450
9 UIKit 0x338f6c18 -[UINavigationTransitionView _navigationTransitionDidStop] + 36
10 UIKit 0x338b4330 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 184
11 UIKit 0x338c0c0e -[UIViewAnimationState animationDidStop:finished:] + 34
12 QuartzCore 0x30a89ea2 run_animation_callbacks(double, void*) + 286
13 QuartzCore 0x30a89d44 CA::timer_callback(__CFRunLoopTimer*, void*) + 116
14 CoreFoundation 0x3148709c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
15 CoreFoundation 0x31486b54 __CFRunLoopDoTimer + 844
16 CoreFoundation 0x314581ae __CFRunLoopRun + 1082
17 CoreFoundation 0x31457c80 CFRunLoopRunSpecific + 224
18 CoreFoundation 0x31457b88 CFRunLoopRunInMode + 52
19 GraphicsServices 0x35d664a4 GSEventRunModal + 108
20 GraphicsServices 0x35d66550 GSEventRun + 56
21 UIKit 0x338d5322 -[UIApplication _run] + 406
22 UIKit 0x338d2e8c UIApplicationMain + 664
23 Wine Brain 0x000021ba 0x1000 + 4538
24 Wine Brain 0x00002184 0x1000 + 4484
As you can see, this is all happening in library code, during an animation for a navigation view controller transition. It seems to happen on a navigate back.
Any ideas on what might cause this that I have control over and what to look for?
Update after some answers
I have this "pattern" whereby I re-use a view controller to show the results of different queries. My code has, say 3 pointers to FetchedResultsController instances, and it has a property currentResults that points to the one being used at the time.
.h file:
#interface MyViewController : UITableViewController <NSFetchedResultsControllerDelegate> {
NSFetchedResultsController *controller1;
NSFetchedResultsController *controller2;
NSFetchedResultsController *controller3;
// and other things unrelated
}
#property (nonatomic, retain) NSFetchedResultsController *currentController;
.m file:
-(void)clearAll {
[controller1 release];
controller1 = nil
[controller2 release];
controller2 = nil
[controller3 release];
controller3 = nil
}
When the caller is going to display my view controller, it firsts configures it for the particulars:
-(void)setupForSearch1 {
self.currentController = [self controller1];
}
- (NSFetchedResultsController *)controller1 {
NSFetchedResultsController *aController = [[[NSFetchedResultsController alloc]
initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:#"titleFirstLetter"
cacheName:nil] autorelease];
// error handling omitted for brevity
controller1 = [aController retain];
return controller1;
}
So, it's actually hard for me to know for sure if I'm doing the right thing; in setupForSearch1, when I assign to the currentController propertly, I believe a release is done on the old reference. And, I've done a release on it in clearAll. But, since I do have two references to it, this seems OK to me.
I get these kind of errors when I release an object i should not - check your release actions.
It looks like the view controller that is about to go away during this animation is over-released. Check to make sure you're not releasing your view controllers too many times.
Whether the .xib mapped correctly? Check your didSelectRowAtIndexPath: part for any issues if you use tableView.
I recently came across this as I was having the same issue, and this answer did not really help me at all.
What turned out to be the problem was that in the view that was being popped from the UINavigationController, there was a variable for a view that was being set each time.
resultsVC = [[ResultsTableViewController alloc]initWithSearchResults:self.resultsArray];
[self.view addSubview:resultsVC.view];
That view would overwrite the previous one, even if it already existed, and add it to the subView. If the old view still existed, it was creating an orphaned view and causing the crash. the solution was to make sure that if that view existed, to remove it from the superview before re-creating it.
[resultsVC.view removeFromSuperview];
resultsVC = nil;
Hope this helps someone that comes after me! thanks
I have an app that only crashes for one of my tester’s - no one else’s. But it crashes consistently for her. It’s very odd.
Details:
She has in iPhone 4 and an iPhone 3Gs
The app crashes on all OSes on BOTH phones
The app crashes with all contacts no matter how they were created
When she sends me her contacts they work fine on both my iPHone 4 and my 3G (not s)
She is the ONLY one that ever gets a crash and it is consistent across both phones and all OSes
She has uninstalled and reinstalled the app and the provisioning profile
She is syncing her iPhone with a windows machine version of iTunes
The crash happens when we use ABPeoplePicker.
From her perspective it looks like the minute she selects a phone number the app crashes.
Of course she is not in our app at that moment. She is in the ABPeoplePicker navigation view provided by Apple.
From the resymbolicated crash log it looks to me like it’s actually crashing when it is trying to return to our app. In other words I can’t find any mention of our app actually being responsible for the crash in the crash log (see below).
It looks like it’s not able to get the index of the selected phone number and then fails when trying to pop back into our app but that’s a guess at best.
I have read the Apple docs and tried to do due diligence in learning about how to read crash logs but I am still stumped.
Here are my questions:
1. Does anyone know what Exception Codes: 0x00000000, 0x00000000 means?
2. Am I correct in assuming that line 9 is where the actual issues is referred to? And if so how do I understand what objc_exception_throw + 64 means?
3. Can anyone shed some light on what this crash log says the problem is?
Incident Identifier:
CrashReporter Key:
Hardware Model: iPhone3,1
Process: My App [471]
Path:
Identifier: My App
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2010-12-06 16:32:44.088 -0600
OS Version: iPhone OS 4.0.2 (8A400)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Thread 0 Crashed:
0 libSystem.B.dylib 0x000791d0 __kill + 8
1 libSystem.B.dylib 0x000791c0 kill + 4
2 libSystem.B.dylib 0x000791b2 raise + 10
3 libSystem.B.dylib 0x0008d6fa abort + 50
4 libstdc++.6.dylib 0x00044a20 __gnu_cxx::__verbose_terminate_handler() + 376
5 libobjc.A.dylib 0x000059ec _objc_terminate + 104
6 libstdc++.6.dylib 0x00042df2 __cxxabiv1::__terminate(void (*)()) + 46
7 libstdc++.6.dylib 0x00042e46 std::terminate() + 10
8 libstdc++.6.dylib 0x00042f16 __cxa_throw + 78
9 libobjc.A.dylib 0x000048cc objc_exception_throw + 64
10 CoreFoundation 0x0001fb72 -[__NSArrayI objectAtIndex:] + 154
11 My App 0x00005a68 0x1000 + 19048
12 My App 0x00005dec 0x1000 + 19948
13 UIKit 0x000668f4 -[UIViewController view] + 104
14 UIKit 0x000784e4 -[UIViewController contentScrollView] + 16
15 UIKit 0x00078354 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 24
16 UIKit 0x00078252 -[UINavigationController _layoutViewController:] + 18
17 UIKit 0x00077d58 -[UINavigationController _startTransition:fromViewController:toViewController:] + 372
18 UIKit 0x00077b68 -[UINavigationController _startDeferredTransitionIfNeeded] + 176
19 UIKit 0x00066fa8 -[UINavigationController pushViewController:transition:forceImmediate:] + 600
20 UIKit 0x00066d40 -[UINavigationController pushViewController:animated:] + 28
21 My App 0x0000a29a 0x1000 + 37530
22 My App 0x0000bcba 0x1000 + 44218
23 AddressBookUI 0x00032cfc -[ABPeoplePickerNavigationController personViewController:shouldPerformDefaultActionForPerson:property:identifier:withMemberCell:] + 152
24 AddressBookUI 0x0003b8ce -[ABPersonViewControllerHelper personTableViewDataSource:selectedPropertyAtIndex:inPropertyGroup:withMemberCell:forEditing:] + 222
25 AddressBookUI 0x0004a17c -[ABPersonTableViewDataSource valueAtIndex:selectedForPropertyGroup:withMemberCell:forEditing:] + 40
26 AddressBookUI 0x00048c00 -[ABPersonTableViewDataSource tableView:didSelectRowAtIndexPath:] + 316
27 UIKit 0x00091f40 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 656
28 UIKit 0x0009db40 -[UITableView _userSelectRowAtIndexPath:] + 124
29 Foundation 0x00086c86 __NSFireDelayedPerform + 362
30 CoreFoundation 0x00071a54 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
31 CoreFoundation 0x00073ede __CFRunLoopDoTimer + 854
32 CoreFoundation 0x0007485e __CFRunLoopRun + 1082
33 CoreFoundation 0x0001d8e4 CFRunLoopRunSpecific + 224
34 CoreFoundation 0x0001d7ec CFRunLoopRunInMode + 52
35 GraphicsServices 0x000036e8 GSEventRunModal + 108
36 GraphicsServices 0x00003794 GSEventRun + 56
37 UIKit 0x000062a0 -[UIApplication _run] + 396
38 UIKit 0x00004e10 UIApplicationMain + 664
39 My App 0x0000d694 0x1000 + 50836
40 My App 0x00002d00 0x1000 + 7424
Here is my ABPeoplePicker code.
#pragma mark ABPeoplePickerNavigationControllerDelegate methods
// Displays the information of a selected person
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
return YES;
}
// Does not allow users to perform default actions such as dialing a phone number, when they select a person property.
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier {
CFStringRef cfName = ABRecordCopyCompositeName(person);
self.selectedName = [NSString stringWithString:(NSString *)cfName];
CFRelease(cfName);
ABMultiValueRef allThePhoneNums = ABRecordCopyValue(person, kABPersonPhoneProperty);
// ABMultiValueGetIndexForIdentifier the exact value of the "identifier" passed to us.
NSString *number = (NSString *)ABMultiValueCopyValueAtIndex(allThePhoneNums, ABMultiValueGetIndexForIdentifier(allThePhoneNums, identifier));
self.selectedNumber = number;
[number release];
CFRelease(allThePhoneNums);
[self showDialOutToPartViewControllerWithName:self.selectedName andNumber:self.selectedNumber];
[peoplePicker dismissModalViewControllerAnimated:YES];
return NO;
}
// Dismisses the people picker and shows the application when users tap Cancel.
- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker; {
[self dismissModalViewControllerAnimated:YES];
}
Foremost, it helps to symbolicate your crash logs using the symbolicatecrash tool and the DSYM file that was generated when you compiled it. I won't discuss how to do that here -- you can search Google to find more details; try "symbolicate crash log DSYM" as keywords.
Once you do that, instead of:
My App 0x0232032+433
It will show something like this:
My App [className callSomeMethod:argument]
Much easier to find the line of code that is spawning the problem.
However - note in the stack trace that the last line of code is [array objectAtIndex:] in Foundation. This method will throw an NSRangeException when you pass an index outside of the bounds of the receiver (e.g. array). From the NSArray docs:
If index is beyond the end of the
array (that is, if index is greater
than or equal to the value returned by
count), an NSRangeException is raised.
So, I'd put my money on that being your crash.
Then the question is - after you symbolicate your crash log - what line of your code is calling an array with an out-of-bounds index?
One of the most frequent crashes of my live app is a crash at MKMapView. It crash at the internal method -[MKMapView mapTileViewDidFinishLoading:]. During my test I could not retrace the crash but is very frequent in the crash reports on iTunes Connect. Has anyboday some experience with this crash? It is only a very simple map showing exactly one annotation.
Here is the complete stacktrace of this crash:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000009
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x339737d8 objc_msgSend + 16
1 MapKit 0x345709ec -[MKMapView mapTileViewDidFinishLoading:]
2 CoreFoundation 0x344492e4 -[NSObject(NSObject) performSelector:withObject:]
3 Foundation 0x3326981e __NSThreadPerformPerform
4 CoreFoundation 0x34460f1e __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
5 CoreFoundation 0x34432ba0 __CFRunLoopDoSources0
6 CoreFoundation 0x34432444 __CFRunLoopRun
7 CoreFoundation 0x34432270 CFRunLoopRunSpecific
8 CoreFoundation 0x34432178 CFRunLoopRunInMode
9 GraphicsServices 0x3026b5ec GSEventRunModal
10 GraphicsServices 0x3026b698 GSEventRun
11 UIKit 0x31ad011c -[UIApplication _run]
12 UIKit 0x31ace128 UIApplicationMain
13 MYApp 0x00002e08 main + 36
14 MYApp 0x00002dd8 start + 32
I think I may have fixed this issue in my own application. It appears that this post has the correct solution and explanation.
The message that was causing the failure in my application was 'mapViewDidFinishLoadingMap' which is a message of the MKMapViewDelegate. Try to set the mapView delegate to 'nil' before in your views dealloc method.
Just do this it will solve the problem 100%
-(void) viewWillDisappear:(BOOL)animated
{
self.mapView.delegate = nil;
mapView=Nil;
NSLog(#"viewWillDisappear");
}
I also had to set the delegate to nil in viewDidDisappear to fix the issue.