A customer of my app sent me this strange crash report and I cannot figure out how this could ever crash. I cannot reproduce the problem myself, so am reliant on the crash report.
It crashes on the following very simple line of code:
UITextField *value = [[UITextField alloc] initWithFrame:frame];
The crash seems to be related to key-value-observing (KVO), but I am not doing anything with that here; it's a simply constructor!
The only possibility I could see, is that another thread is writing to a dealloc'ed object that happens to have the same memory address as an object that is created by the initWithFrame:. But in the crash report, all other threads are quiet.
I have found other similar questions, but none of them have an answer.
Any ideas?
Here are the relevant parts from the crash report:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000010
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x0000000181981b90 objc_msgSend + 16
1 Foundation 0x0000000182bf2454 -[NSObject(NSKeyValueObserverNotification) willChangeValueForKey:] + 324
2 QuartzCore 0x0000000184deb11c CA::Layer::set_delegate(objc_object*) + 72
3 UIKit 0x0000000187456f40 -[UIView _createLayerWithFrame:] + 580
4 UIKit 0x0000000187456a00 UIViewCommonInitWithFrame + 688
5 UIKit 0x00000001874566f0 -[UIView initWithFrame:] + 140
6 UIKit 0x000000018745dfb0 -[UILabel initWithFrame:] + 48
7 UIKit 0x0000000187542064 -[UITextField createTextLabelWithTextColor:] + 76
8 UIKit 0x0000000187541c30 -[UITextField initWithFrame:] + 416
9 Flyskyhy 0x00000001000e1f68 -[ElementView doInitWithUnit:] (ElementView.m:178)
Related
I am working on iBeacon technology and SIGTRAP occurred at "[CoreLocationHandler locationManager:didRangeBeacons:inRegion:]" delegate method.
Inside this delegate method I am running a task over DISPATCH_QUEUE_SERIAL, and using #autoreleasepool block to save data locally.
This queue is returned by a static method of a singleton class, so I am not releasing this queue anywhere since various classes are using it. But still I am receiving SIGTRAP crash. Following is the important info regarding crash report.
CRASH REPORT
Date/Time: 2015-11-18 06:34:02.920 +0000
Launch Time: 2015-11-18 06:28:56.798 +0000
OS Version: iOS 8.0.2 (12A405)
Report Version: 105
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000000000defe
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:<br/>
0 libdispatch.dylib 0x3276f6ac _os_object_retain + 32
1 libobjc.A.dylib 0x32229474 objc_retainAutoreleaseReturnValue + 4
2 MyApp 0x000cf020 -[BusinessLayer initWithBeaconArray:withLocationManager:withDelegate:] (BusinessLayer.m:81)
3 MyApp 0x000e51fe -[CoreLocationHandler locationManager:didRangeBeacons:inRegion:] (CoreLocationHandler.m:319)
4 CoreLocation 0x2522049e 0x25212000 + 58526
5 CoreLocation 0x2521ad06 0x25212000 + 36102
6 CoreLocation 0x25214af4 0x25212000 + 10996
7 CoreFoundation 0x24b275b2 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 10
8 CoreFoundation 0x24b26874 __CFRunLoopDoBlocks + 212
9 CoreFoundation 0x24b253ae __CFRunLoopRun + 1710
10 CoreFoundation 0x24a7361c CFRunLoopRunSpecific + 472
11 CoreFoundation 0x24a7342e CFRunLoopRunInMode + 102
12 GraphicsServices 0x2be220a4 GSEventRunModal + 132
13 UIKit 0x2805e354 UIApplicationMain + 1436
14 MyApp 0x000e815c main (main.m:16)
15 libdyld.dylib 0x3278eaac start + 0
I've got a crash that, according to the crash report, isn't my fault. I wish that were true. I've Profiled the app with NSZombies and it hasn't happened there. Here are excerpts from the crash report:
Date/Time: 2015-11-23 19:40:34.34 -0600
Launch Time: 2015-11-23 18:49:43.43 -0600
OS Version: iOS 9.1 (13B143)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000c
Triggered by Thread: 7
Thread 7 Crashed:
0 libobjc.A.dylib 0x34fcbac6 objc_msgSend + 6
1 UIFoundation 0x31e7242e +[NSStringDrawingTextStorageSettings threadSpecificStringDrawingTextStorageSettings:] + 62
2 UIFoundation 0x31e675de +[NSString(NSStringDrawing) typesetterBehavior] + 34
3 UIFoundation 0x31e68ae2 __NSStringDrawingEngine + 298
4 UIFoundation 0x31e68908 -[NSString(NSExtendedStringDrawing) drawWithRect:options:attributes:context:] + 144
5 UIKit 0x276aa488 -[UILabel _drawTextInRect:baselineCalculationOnly:] + 4864
6 UIKit 0x2771b40c -[UILabel drawTextInRect:] + 540
7 UIKit 0x2771b1e4 -[UILabel drawRect:] + 88
8 UIKit 0x2771b15e -[UIView(CALayerDelegate) drawLayer:inContext:] + 386
9 QuartzCore 0x26f8b6fc -[CALayer drawInContext:] + 228
10 QuartzCore 0x26f75088 CABackingStoreUpdate_ + 1852
11 QuartzCore 0x270619d0 ___ZN2CA5Layer8display_Ev_block_invoke + 52
12 QuartzCore 0x26f745c8 CA::Layer::display_() + 1168
13 QuartzCore 0x26f588a0 CA::Layer::display_if_needed(CA::Transaction*) + 204
14 QuartzCore 0x26f58560 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
15 QuartzCore 0x26f57a78 CA::Context::commit_transaction(CA::Transaction*) + 368
16 QuartzCore 0x26f5772a CA::Transaction::commit() + 614
17 QuartzCore 0x26f84ed2 CA::Transaction::release_thread(void*) + 310
18 libsystem_pthread.dylib 0x3589e54c _pthread_tsd_cleanup + 508
19 libsystem_pthread.dylib 0x3589e14e _pthread_exit + 86
20 libsystem_pthread.dylib 0x3589db3c _pthread_wqthread + 1044
21 libsystem_pthread.dylib 0x3589d718 start_wqthread + 8
My application isn't listed in here anywhere within the crashed thread. I have a few questions:
How do I interpret this report to find the trigger of the crash? I see UILabels referenced in there, and I have plenty of those, how would I know which might be the cause?
Is the crash one of the lines in the middle and the report is showing actions before and after to provide context?
Thank you for your help. This debugging is confusing stuff.
Update: 11/27/15:
Do I need to make sure a declaration like the following is done on the main thread:
UIView *lineView;
or only the modifications like the following:
lineView = [[UIView alloc] initWithFrame:CGRectMake(15, cell.contentView.frame.size.height - 1.0, cell.contentView.frame.size.width, 1)];
I'm having trouble determining what needs to be wrapped in GCD dispatches and what can be done on a background thread. I've been making changes per the suggested answer but I'm still getting the same crash.
Thanks.
You are crashing because you violated the rule that UIView descendants can only be manipulated on the main thread. Crashing isn't necessarily the only outcome, but in Apple's view, it's perfectly acceptable.
Fix your code so that it dispatches that bit of work to the main thread.
I had a user running my app on his iPhone 5. He performed a backup with iTunes. Bought a new iPhone 6S and restored from his iTunes backup.
When he launches my app it immediately crashes during launch. I got the crash logs from him, but there is no error message. It's crashing during the auto-generated -applicationDocumentsDirectory function in my AppDelegate.
- (NSURL *)applicationDocumentsDirectory
{
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
Is there any way for me to determine what actually went wrong to see if it's something I can fix?
Incident Identifier: 3A0D56CA-EEAF-4F5A-8D16-D182E61034D5
CrashReporter Key: 9f4ce42b70e98d925f135c618394817f9451767b
Hardware Model: iPhone8,1
Process: MyApp [1198]
Path: /private/var/mobile/Containers/Bundle/Application/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/MyApp.app/MyApp
Identifier: com.inadaydevelopment.myapp
Version: 1.0.1 (1.0)
Code Type: ARM-64 (Native)
Parent Process: launchd [1]
Date/Time: 2015-10-02 14:30:25.25 -0700
Launch Time: 2015-10-02 14:30:25.25 -0700
OS Version: iOS 9.0.1 (13A405)
Report Version: 105
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Filtered syslog:
None found
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x000000019950b1e0 __pthread_kill + 8
1 libsystem_pthread.dylib 0x00000001995d4f0c pthread_kill + 112
2 libsystem_c.dylib 0x000000019947eb78 abort + 140
3 MyApp 0x000000010001ef7c -[AppDelegate applicationDocumentsDirectory] (AppDelegate.m:517)
4 MyApp 0x000000010001eae8 -[AppDelegate managedObjectContext] (AppDelegate.m:430)
5 MyApp 0x000000010002d004 -[BaseViewController awakeFromNib] (BaseViewController.m:54)
6 UIKit 0x00000001890e6058 -[UINib instantiateWithOwner:options:] + 2188
7 UIKit 0x0000000189324ea0 -[UIStoryboard instantiateViewControllerWithIdentifier:] + 196
8 UIKit 0x0000000189325000 -[UIStoryboard instantiateInitialViewController] + 68
9 UIKit 0x0000000188edd178 -[UIApplication _loadMainStoryboardFileNamed:bundle:] + 108
10 UIKit 0x0000000188caee40 -[UIApplication _loadMainInterfaceFile] + 264
11 UIKit 0x0000000188edc068 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1316
12 UIKit 0x0000000188ed9300 -[UIApplication workspaceDidEndTransaction:] + 168
13 FrontBoardServices 0x000000018d7737ec -[FBSSerialQueue _performNext] + 184
14 FrontBoardServices 0x000000018d773b6c -[FBSSerialQueue _performNextFromRunLoopSource] + 56
15 CoreFoundation 0x000000018369c5a4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
16 CoreFoundation 0x000000018369c038 __CFRunLoopDoSources0 + 540
17 CoreFoundation 0x0000000183699d38 __CFRunLoopRun + 724
18 CoreFoundation 0x00000001835c8dc0 CFRunLoopRunSpecific + 384
19 UIKit 0x0000000188ca80c8 -[UIApplication _run] + 460
20 UIKit 0x0000000188ca2f60 UIApplicationMain + 204
21 MyApp 0x000000010001bdd0 main (main.m:16)
22 libdyld.dylib 0x00000001993ee8b8 start + 4
Crashes without any useful stacktrace often happen when a message is sent to a deallocated instance. I struggled with this a few weeks ago when messing around with a UIViewController category.
Of course, you are right, a message sent to nil doesn't do no harm. A message sent to a deallocated instance of sth on the other hand leads to a crash.
Try turning ZombieObjects on, then you will get a log when this occurs, which can help you find the bug.
I have a storyboard-based app, for which I have created custom segues, which use a custom animation controller that I have created.
Everything works fine when segueing forward/unwinding back one screen at a time. However, when I try to unwind through a stack of screens (e.g. I had segued First->Second->Third and then try to unwind back Third->First), I get an EXC_BAD_ACCESS (code=1) error.
The Apple documentation for UIViewController.dismissViewControllerAnimated (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/index.html#//apple_ref/occ/instm/UIViewController/dismissViewControllerAnimated:completion:) says that
If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
So as I understand this, if I call ‘dismissViewControllerAnimated’ on First, it should dismiss Third using its modal transition style, and just remove Second from the stack.
Therefore my UnwindSegue.perform method is:
- (void)perform {
UIViewController *sourceViewController = self.sourceViewController;
UIViewController *destinationViewController = self.destinationViewController;
sourceViewController.modalPresentationStyle = UIModalPresentationFullScreen;
sourceViewController.transitioningDelegate = self;
[destinationViewController dismissViewControllerAnimated:YES completion:nil]; //Error occurs here
}
The last line crashes with the EXC_BAD_ACCESS error.
I’ve done some digging around (by enabling zombies), and it seems like UIViewController internally has a weak reference to my ‘forward’ segue -
FirstController.dismissViewControllerAnimated calls UIViewController._customAnimatorForDismissedController, which calls methods on the segue Second->Third (which no longer exists).
Anyone got any idea on whether this behaviour is expected, or where I'm going wrong? Everything works in iOS7.
ETA: Crash log
Incident Identifier: 821DC9AC-E1A1-4CCD-8A3F-718577C1634D
CrashReporter Key: 35442db1a2bdce63197d4abe696619ca29fe9675
Hardware Model: iPad4,1
Process: TestProject [3792]
Path: /private/var/mobile/Containers/Bundle/Application/B56179DF-3A3D-4C57-A5A0-910EF0BAEB8D/TestProject.app/TestProject
Identifier: com.xyz.TestProject
Version: 1 (1.0)
Code Type: ARM-64 (Native)
Parent Process: launchd [1]
Date/Time: 2015-02-10 17:32:35.524 +0000
Launch Time: 2015-02-10 17:32:15.301 +0000
OS Version: iOS 8.1.2 (12B440)
Report Version: 105
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000000554fbeb8
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x0000000197cd7bd0 objc_msgSend + 16
1 UIKit 0x000000018bb83c3c -[UIViewController _customAnimatorForDismissedController:] + 80
2 UIKit 0x000000018bb83a84 -[UIViewController _dismissViewControllerWithTransition:from:completion:] + 620
3 UIKit 0x000000018bb2c074 -[UIViewController dismissViewControllerWithTransition:completion:] + 948
4 UIKit 0x000000018bb2bc5c -[UIViewController dismissViewControllerAnimated:completion:] + 248
5 TestProject 0x00000001000cd768 -[XYZUnwindStoryboardSegue perform] (XYZUnwindStoryboardSegue.m:26)
6 UIKit 0x000000018ba90d30 -[UIApplication sendAction:to:from:forEvent:] + 92
7 UIKit 0x000000018ba79e44 -[UIControl _sendActionsForEvents:withEvent:] + 608
8 UIKit 0x000000018ba906cc -[UIControl touchesEnded:withEvent:] + 588
9 UIKit 0x000000018ba90358 -[UIWindow _sendTouchesForEvent:] + 696
10 UIKit 0x000000018ba898ac -[UIWindow sendEvent:] + 680
11 UIKit 0x000000018ba5cfa4 -[UIApplication sendEvent:] + 260
12 UIKit 0x000000018bcfbf54 _UIApplicationHandleEventFromQueueEvent + 14988
13 UIKit 0x000000018ba5b50c _UIApplicationHandleEventQueue + 1612
14 CoreFoundation 0x00000001872629e8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 20
15 CoreFoundation 0x0000000187261c8c __CFRunLoopDoSources0 + 260
16 CoreFoundation 0x000000018725fd3c __CFRunLoopRun + 708
17 CoreFoundation 0x000000018718d0a0 CFRunLoopRunSpecific + 392
18 GraphicsServices 0x00000001902f35a0 GSEventRunModal + 164
19 UIKit 0x000000018bac23bc UIApplicationMain + 1484
20 TestProject 0x00000001000ce7ec main (main.m:14)
21 libdyld.dylib 0x0000000198332a04 start + 0
Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0 libsystem_kernel.dylib 0x0000000198430c94 kevent64 + 8
1 libdispatch.dylib 0x0000000100141254 0x100130000 + 70228
2 libdispatch.dylib 0x0000000100132ef4 0x100130000 + 12020
Thread 2:
0 libsystem_kernel.dylib 0x000000019844bc78 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x00000001984e5390 _pthread_wqthread + 988
2 libsystem_pthread.dylib 0x00000001984e4fa4 start_wqthread + 0
I got a crash log from a user, and I do not see any function names - only pointers in hex:
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x30a29c98 0x30a27000 + 11416
1 UIKit 0x3517b4ee 0x35167000 + 83182
2 UIKit 0x3518eddc 0x35167000 + 163292
3 UIKit 0x3523a84a 0x35167000 + 866378
4 CoreFoundation 0x32368c3c 0x32366000 + 11324
5 UIKit 0x3517b5ee 0x35167000 + 83438
6 UIKit 0x3518eddc 0x35167000 + 163292
7 UIKit 0x3523a70c 0x35167000 + 866060
How can I get the crash log to show more meaningful info ?
This should point you in the right direction:
Technical Note TN2151 - Understanding and Analyzing iPhone OS Application Crash Reports