iPhone crash during layer animation after being in background - ios

I'm having trouble fixing a pesky crash. I can't figure out how to accurately reproduce it,
but it only occurs after the app comes out of the background. I get this crash every 2+ days.
In applicationDidBecomeActive:, I restart a timer that fires every 0.4 seconds. It calls:
- (void)rotate {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
self.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(-[LocationModel instance].heading.magneticHeading));
[UIView commitAnimations];
}
Also in RotateView, is the drawRect, whose body is at line 41 as seen in the crash report.
- (void)drawRect:(CGRect)rect {
[img drawInRect:rect]; // line 41
}
img is a small UIImage loaded with imageNamed: and stored in an ivar.
Any advice? I have little experience with crash reports.
Thanks!
Crash report:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x3001b482
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x333a6c98 objc_msgSend + 16
1 MyApp 0x000259bc -[RotateView drawRect:] (RotateView.m:41)
2 UIKit 0x34f4a9fe -[UIView(CALayerDelegate) drawLayer:inContext:] + 258
3 QuartzCore 0x3058efa6 -[CALayer drawInContext:] + 86
4 QuartzCore 0x3058ed24 _ZL16backing_callbackP9CGContextPv + 32
5 QuartzCore 0x3058e776 CABackingStoreUpdate + 1226
6 QuartzCore 0x3058e178 -[CALayer _display] + 724
7 QuartzCore 0x3058de86 -[CALayer display] + 134
8 QuartzCore 0x30582706 CALayerDisplayIfNeeded + 178
9 QuartzCore 0x305821c6 CA::Context::commit_transaction(CA::Transaction*) + 214
10 QuartzCore 0x30581fd0 CA::Transaction::commit() + 184
11 QuartzCore 0x30580900 CA::Transaction::pop() + 120
12 QuartzCore 0x3058087e +[CATransaction commit] + 22
13 UIKit 0x35096bcc _UIWindowUpdateVisibleContextOrder + 136
14 UIKit 0x35096c60 +[UIWindow _prepareWindowsForAppResume] + 4
15 UIKit 0x3508f3de -[UIApplication _handleApplicationResumeEvent:] + 66
16 UIKit 0x34f39e20 -[UIApplication handleEvent:withNewEvent:] + 2724
17 UIKit 0x34f3920e -[UIApplication sendEvent:] + 38
18 UIKit 0x34f38c4c _UIApplicationHandleEvent + 5084
19 GraphicsServices 0x35873e70 PurpleEventCallback + 660
20 GraphicsServices 0x35873efa PurpleEventSignalCallback + 10
21 CoreFoundation 0x36126a72 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
22 CoreFoundation 0x36128758 __CFRunLoopDoSources0 + 376
23 CoreFoundation 0x361294e4 __CFRunLoopRun + 224
24 CoreFoundation 0x360b9ebc CFRunLoopRunSpecific + 224
25 CoreFoundation 0x360b9dc4 CFRunLoopRunInMode + 52
26 GraphicsServices 0x35873418 GSEventRunModal + 108
27 GraphicsServices 0x358734c4 GSEventRun + 56
28 UIKit 0x34f63d62 -[UIApplication _run] + 398
29 UIKit 0x34f61800 UIApplicationMain + 664
30 MyApp 0x000026c4 main (main.m:14)
31 MyApp 0x0000266c start + 32

EXC_BAD_ACCESS generally means you released an object then called that object later. Try enabling NSZombies to find it. There are numerous tutorials on how to do it. Here's one to start http://www.touch-code-magazine.com/how-to-debug-exc_bad_access/

Related

EXC_BREAKPOINT due to a wrong conversion

While checking the issues reported by Crashlytics, it seems that I have a EXC_BREAKPOINT error for the following line:
self.caloriesFor100 = Int((cartFood.nbCalories.floatValue / 100) * cartFood.quantite.floatValue)
caloriesFor100 is a Int.
cartFood.nbCalories is an NSNumber which is supposed to have float values.
cartFood.quantite is also an NSNumber which is supposed to have float values.
I did not succeed to reproduce the issue. What could possibly cause an EXC_BREAKPOINT in this code?
Full stack trace:
Crashed: com.apple.main-thread
0 LSDP 0x10269ccbc specialized CartFoodModelinit(_:) (CartFoodModel.swift:88)
1 LSDP 0x10268a570 specialized CartFoodCell.cartFoodObjc (CartFoodModel.swift)
2 LSDP 0x102689600 #objc CartFoodCell.cartFoodObjc (<compiler-generated>)
3 LSDP 0x102664c7c -[PanierDuJourViewController tableView:cellForRowAtIndexPath:] (PanierDuJourViewController.m:156)
4 UIKit 0x18bf10148 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 668
5 UIKit 0x18bf0fe00 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80
6 UIKit 0x18bf0eb1c -[UITableView _updateVisibleCellsNow:isRecursive:] + 2280
7 UIKit 0x18bf0a668 -[UITableView layoutSubviews] + 140
8 UIKit 0x18be47770 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1420
9 QuartzCore 0x1863e925c -[CALayer layoutSublayers] + 184
10 QuartzCore 0x1863ed3ec CA::Layer::layout_if_needed(CA::Transaction*) + 324
11 QuartzCore 0x186359aa0 CA::Context::commit_transaction(CA::Transaction*) + 320
12 QuartzCore 0x1863815d0 CA::Transaction::commit() + 580
13 UIKit 0x18c22054c _UIApplicationFlushRunLoopCATransactionIfTooLate + 172
14 UIKit 0x18c7fd4c0 __handleEventQueueInternal + 5520
15 UIKit 0x18c7f6258 __handleHIDEventFetcherDrain + 152
16 CoreFoundation 0x18221b404 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
17 CoreFoundation 0x18221ac2c __CFRunLoopDoSources0 + 276
18 CoreFoundation 0x18221879c __CFRunLoopRun + 1204
19 CoreFoundation 0x182138da8 CFRunLoopRunSpecific + 552
20 GraphicsServices 0x18411b020 GSEventRunModal + 100
21 UIKit 0x18c11978c UIApplicationMain + 236
22 LSDP 0x1025fce28 main (main.m:16)
23 libdyld.dylib 0x181bc9fc0 start + 4
You may catch this exception in case if NSNumber property will be nil. So maybe it is better to change nbCalories to has an option value.
I found a similar problem and its solution here.
Since your app crashes at tableView:cellForRowAtIndexPath:, it might be that the cell should display an entry of your table (CartFoodCell.cartFoodObjc) that no longer exists.
But without more code, this is just a guess. Please double check it in your code.

EXC_BAD_ACCESS KERN_INVALID_ADDRESS iOS crash

I am getting below crash logs across all iOS versions. However, I am not able to figure out the exact cause of this. Is it something to do with accessing a de-allocated object? If yes, is there a way to replicate the scenario since I am not able to.
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x180771b90 objc_msgSend + 16
1 CoreGraphics 0x182574568 CGColorRetain + 28
2 CoreGraphics 0x182609088 CGGStateSetStrokeColor + 64
3 UIKit 0x186893698 -[UIKBHandwritingStrokeView drawRect:] + 692
4 UIKit 0x1862e2678 -[UIView(CALayerDelegate) drawLayer:inContext:] + 368
5 QuartzCore 0x183c16228 -[CALayer drawInContext:] + 260
6 QuartzCore 0x183c008ac CABackingStoreUpdate_ + 2432
7 QuartzCore 0x183d18360 ___ZN2CA5Layer8display_Ev_block_invoke + 52
8 QuartzCore 0x183bffa88 CA::Layer::display_() + 1368
9 QuartzCore 0x183be17a8 CA::Layer::display_if_needed(CA::Transaction*) + 228
10 QuartzCore 0x183be1494 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 44
11 QuartzCore 0x183be0ab8 CA::Context::commit_transaction(CA::Transaction*) + 252
12 QuartzCore 0x183be0818 CA::Transaction::commit() + 500
13 UIKit 0x186256ff4 _UIApplicationHandleEventQueue + 4980
14 CoreFoundation 0x1810b109c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
15 CoreFoundation 0x1810b0b30 __CFRunLoopDoSources0 + 540
16 CoreFoundation 0x1810ae830 __CFRunLoopRun + 724
17 CoreFoundation 0x180fd8c50 CFRunLoopRunSpecific + 384
18 GraphicsServices 0x1828c0088 GSEventRunModal + 180
19 UIKit 0x1862c2088 UIApplicationMain + 204
20 Smartphone 0x1000e0b78 main (main.m:13)
21 libdispatch.dylib 0x180b768b8 (Missing)
Also I am not able to figure out where exactly the crash is happening. Since I am getting these as part of release build.

iOS app odd crashes [UINavigationController _startCustomTransition:]

I have my app in alpha test, and using fabric to capture the crash logs. I had encountered a crash, and I have the below trace but have no idea what is going on. I tried to reproduce it with Xcode, but hardly can reproduce.
Could any one help on this? or share some ideas?
Thread : Crashed: com.apple.main-thread
0 libsystem_platform.dylib 0x0000000197c7d8d4 OSAtomicCompareAndSwap32Barrier + 12
1 libobjc.A.dylib 0x0000000197468120 realizeClass(objc_class*) + 100
2 libobjc.A.dylib 0x000000019746c930 lookUpImpOrForward + 224
3 libobjc.A.dylib 0x0000000197477db8 _objc_msgSend_uncached_impcache + 56
4 UIKit 0x000000018b66bef4 -[UINavigationController _startCustomTransition:] + 972
5 UIKit 0x000000018b57d630 -[UINavigationController _startDeferredTransitionIfNeeded:] + 468
6 UIKit 0x000000018b57d3fc -[UINavigationController __viewWillLayoutSubviews] + 56
7 UIKit 0x000000018b57d37c -[UILayoutContainerView layoutSubviews] + 200
8 UIKit 0x000000018b4c5d2c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 572
9 QuartzCore 0x000000018ae1d994 -[CALayer layoutSublayers] + 168
10 QuartzCore 0x000000018ae18564 CA::Layer::layout_if_needed(CA::Transaction*) + 320
11 QuartzCore 0x000000018ae18408 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
12 QuartzCore 0x000000018ae17c08 CA::Context::commit_transaction(CA::Transaction*) + 276
13 QuartzCore 0x000000018ae1798c CA::Transaction::commit() + 436
14 UIKit 0x000000018b4c7c48 _UIApplicationHandleEventQueue + 1700
15 CoreFoundation 0x0000000186cd29ec __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
16 CoreFoundation 0x0000000186cd1c90 __CFRunLoopDoSources0 + 264
17 CoreFoundation 0x0000000186ccfd40 __CFRunLoopRun + 712
18 CoreFoundation 0x0000000186bfd0a4 CFRunLoopRunSpecific + 396
19 GraphicsServices 0x000000018fd975a4 GSEventRunModal + 168
20 UIKit 0x000000018b52eaa4 UIApplicationMain + 1488
21 MCompass 0x00000001001631c8 main (main.m:16)
22 libdyld.dylib 0x0000000197ad2a08 start + 4
It is hard to tell without seeing some more details, but maybe this can help: http://aplus.rs/2013/beware-a-crashing-bug-lurks-with-uinavigationcontroller-transitions/

UIkit crashes also not able to reproduce

Thread 0: Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x3a6285b0 objc_msgSend + 15
1 UIKit 0x348285f5 -[UINavigationController _startTransition:fromViewController:toViewController:] + 92
2 UIKit 0x348284c1 -[UINavigationController _startDeferredTransitionIfNeeded:] + 324
3 UIKit 0x347f94e9 -[UILayoutContainerView layoutSubviews] + 180
4 UIKit 0x347b8803 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 258
5 QuartzCore 0x34562d8b -[CALayer layoutSublayers] + 214
6 QuartzCore 0x34562929 CA::Layer::layout_if_needed(CA::Transaction*) + 460
7 QuartzCore 0x3456385d CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
8 QuartzCore 0x34563243 CA::Context::commit_transaction(CA::Transaction*) + 238
9 QuartzCore 0x34563051 CA::Transaction::commit() + 316
10 UIKit 0x34988369 -[UIApplication _sendOrderedOutContextsAndInvalidate:] + 112
11 UIKit 0x3483863f orderOutContextObserverCallout + 34
12 CoreFoundation 0x329826cd __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
13 CoreFoundation 0x329809c1 __CFRunLoopDoObservers + 276
14 CoreFoundation 0x32980c91 __CFRunLoopRun + 608
15 CoreFoundation 0x328f3ebd CFRunLoopRunSpecific + 356
16 CoreFoundation 0x328f3d49 CFRunLoopRunInMode + 104
17 GraphicsServices 0x364a62eb GSEventRunModal + 74
18 UIKit 0x34809301 UIApplicationMain + 1120
19 test 0x000f610f main (main.m:16)
I get this error in my crashlytics but not able to reproduce this error. Can any one help me to solve this how can i get rid of this crash.

iOS - Determining the cause of a crash (from a crash report) in _WebTryThreadLock

I have been trying to figure out what is causing one of the top crashes in my iOS application. It looks like there is some layout happening on a background thread which is causing it to crash. Is there any way to determine what I might be doing that is triggering this relayout? I assume from the stack that it is related to a UIWebView when my app is being brought back into the foreground.
Other stackoverflow threads on the topic seem to mention things like triggering a table reload on a background thread. As far as I can see all the webView delegate methods get called on the main thread. Is there some case where this is not true or are there some other methods which get called on a background thread and I'm just not aware?
Web Thread - Crashed.
0 WebCore _WebTryThreadLock(bool) + 297
1 WebCore _WebTryThreadLock(bool) + 288
2 WebCore WebThreadLock + 66
3 UIKit -[UIWebDocumentView(UIWebDocumentViewTextSelecting) selectionBaseWritingDirection] + 10
4 UIKit -[UITextField _currentTextAlignment] + 86
5 UIKit -[UITextField _showsClearButtonWhenNonEmpty:] + 58
6 UIKit -[UITextField _textRectForBounds:forEditing:] + 678
7 UIKit -[UITextField editingRectForBounds:] + 52
8 UIKit -[UITextField editRect] + 70
9 UIKit -[UITextField layoutSubviews] + 1320
10 UIKit -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 258
11 QuartzCore -[CALayer layoutSublayers] + 214
12 QuartzCore CA::Layer::layout_if_needed(CA::Transaction*) + 460
13 QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
14 QuartzCore CA::Context::commit_transaction(CA::Transaction*) + 238
15 QuartzCore CA::Transaction::commit() + 316
16 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 60
17 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
18 CoreFoundation __CFRunLoopDoObservers + 276
19 CoreFoundation CFRunLoopRunSpecific + 394
20 CoreFoundation CFRunLoopRunInMode + 104
21 WebCore RunWebThread(void*) + 444
22 libsystem_c.dylib pthread_start + 308
Main - Thread
0 libsystem_kernel.dylib __psynch_mutexwait + 24
1 libsystem_c.dylib pthread_mutex_lock + 392
2 WebCore _WebTryThreadLock(bool) + 336
3 WebCore WebThreadLock + 66
4 WebKit -[WebDatabasePauser applicationWillEnterForeground] + 16
5 CoreFoundation _CFXNotificationPost + 1426
6 Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] + 72
7 UIKit -[UIApplication _sendWillEnterForegroundCallbacks] + 154
8 UIKit -[UIApplication _handleApplicationResumeEvent:] + 1094
9 UIKit -[UIApplication handleEvent:withNewEvent:] + 1292
10 UIKit -[UIApplication sendEvent:] + 72
11 UIKit _UIApplicationHandleEvent + 6154
12 GraphicsServices _PurpleEventCallback + 590
13 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
14 CoreFoundation __CFRunLoopDoSources0 + 212
15 CoreFoundation __CFRunLoopRun + 646
16 CoreFoundation CFRunLoopRunSpecific + 356
17 CoreFoundation CFRunLoopRunInMode + 104
18 GraphicsServices GSEventRunModal + 74
19 UIKit UIApplicationMain + 1120
20 AppName main.m line 23
It seems you are updating UI on the background thread, in your code add this line wherever you are updating your UI and you are fetching data on the background thread:
dispatch_async(dispatch_get_main_queue(), ^{
// Update data here
});
As soon as you, rather code feels that data is there on device and it's time to update the UI corresponding to new data then try and bring back main thread in action.
Hope it helps.

Resources