Does anynone know how to fix this issue? There are so many crashes posted to Fabric, which only appeared on iOS 11. Fabric gives a tip:
This crash has non-main threads that appear to use UIKit classes or functions. Generally speaking, it is only safe to use UIKit from the main thread. Calling into UIKit from background threads can cause unpredictable behavior (like crashes!). Please double check that all of your code (that is not on the main thread) has been explicitly marked as safe to use in the background by Apple.
Below is the crash session:
Crashed: WebThread
0 libobjc.A.dylib 0x1845041a0 objc_retain + 16
1 UIKit 0x18e850a10 -[UIView(Hierarchy) subviews] + 76
2 UIKit 0x18eb4416c -[UIView(CALayerDelegate) _wantsReapplicationOfAutoLayoutWithLayoutDirtyOnEntry:] + 72
3 UIKit 0x18e856e60 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1348
4 QuartzCore 0x1892e3948 -[CALayer layoutSublayers] + 184
5 QuartzCore 0x1892e7ad0 CA::Layer::layout_if_needed(CA::Transaction*) + 332
6 QuartzCore 0x18925431c CA::Context::commit_transaction(CA::Transaction*) + 336
7 QuartzCore 0x18927bb40 CA::Transaction::commit() + 540
8 QuartzCore 0x18927c980 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
9 CoreFoundation 0x185246cdc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
10 CoreFoundation 0x185244694 __CFRunLoopDoObservers + 412
11 CoreFoundation 0x185164c78 CFRunLoopRunSpecific + 468
12 WebCore 0x18d0d984c RunWebThread(void*) + 560
13 libsystem_pthread.dylib 0x184ec82b4 _pthread_body + 308
14 libsystem_pthread.dylib 0x184ec8180 _pthread_body + 310
15 libsystem_pthread.dylib 0x184ec6b74 thread_start + 4
Related
I am getting a crash report in Crashlytics as below.
I tried a lot of ways generating this crash, but I am not able to generate this crash
Crashed: com.apple.main-thread
0 MyApp 0x1010d4b1c specialized Collection.firstIndex(where:) + 2433 (MyViewController.swift:2433)
1 MyApp 0x101094ee4 MyViewController.collectionView(_:cellForItemAt:) + 4307881700 (<compiler-generated>:4307881700)
2 MyApp 0x1010c2df4 #objc MyViewController.collectionView(_:cellForItemAt:) + 4308069876
3 UIKitCore 0x1aba8ae74 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 424
4 UIKitCore 0x1aba8f6f0 -[UICollectionView _updateVisibleCellsNow:] + 4352
5 UIKitCore 0x1aba93fbc -[UICollectionView layoutSubviews] + 320
6 UIKitCore 0x1ac6bc17c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2140
7 QuartzCore 0x1aec242c0 -[CALayer layoutSublayers] + 284
8 QuartzCore 0x1aec2a43c CA::Layer::layout_if_needed(CA::Transaction*) + 480
9 QuartzCore 0x1aec35140 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 136
10 QuartzCore 0x1aeb7d884 CA::Context::commit_transaction(CA::Transaction*, double) + 304
11 QuartzCore 0x1aeba7574 CA::Transaction::commit() + 676
12 QuartzCore 0x1aeba7f68 CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
13 CoreFoundation 0x1a811de68 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
14 CoreFoundation 0x1a8118d54 __CFRunLoopDoObservers + 416
15 CoreFoundation 0x1a8119320 __CFRunLoopRun + 1308
16 CoreFoundation 0x1a8118adc CFRunLoopRunSpecific + 464
17 GraphicsServices 0x1b20b9328 GSEventRunModal + 104
18 UIKitCore 0x1ac22663c UIApplicationMain + 1936
19 MyApp 0x100d80fa8 main + 30 (MyDatabase.swift:30)
20 libdyld.dylib 0x1a7fa2360 start + 4
Below is the line where the report says on which the crash has been generated.
if let index = cell.array.firstIndex(where: {$0.name == self.name}){
//code here
}
I looked for a lot of solutions out there but couldn't find any right solution for myself.
Thanks!
We have crash in AVFoundation.
AVFoundation
+[AVOutputContext(FigRoutingContext) currentRoutingContextFactory]
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000a3c27beb8
Crashed: Thread
0 libobjc.A.dylib 0x183b8c910 objc_msgSend + 16
1 AVFoundation 0x18a5401bc +[AVOutputContext(FigRoutingContext) currentRoutingContextFactory] + 56
2 AVFoundation 0x18a53ae28 +[AVFigRoutingContextOutputContextImpl sharedAudioPresentationOutputContext] + 28
3 AVFoundation 0x18a4d0a24 +[AVOutputContext sharedAudioPresentationOutputContext] + 40
4 MediaPlayer 0x195deb1cc -[MPAVLightweightRoutingController pickedRoutes] + 68
5 MediaPlayer 0x195e04338 -[MPVolumeView _setShowsVolumeSlider:] + 96
6 MediaPlayer 0x195e02ad4 -[MPVolumeView layoutSubviews] + 208
7 UIKit 0x18e593770 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1420
8 QuartzCore 0x188b3525c -[CALayer layoutSublayers] + 184
9 QuartzCore 0x188b393ec CA::Layer::layout_if_needed(CA::Transaction*) + 324
10 QuartzCore 0x188aa5aa0 CA::Context::commit_transaction(CA::Transaction*) + 320
11 QuartzCore 0x188acd5d0 CA::Transaction::commit() + 580
12 QuartzCore 0x188acdd10 CA::Transaction::release_thread(void*) + 244
13 libsystem_pthread.dylib 0x1845e457c _pthread_tsd_cleanup + 572
14 libsystem_pthread.dylib 0x1845e42cc _pthread_exit + 88
15 libsystem_pthread.dylib 0x1845e40d4 _pthread_wqthread + 1472
16 libsystem_pthread.dylib 0x1845e3b08 start_wqthread + 4
The Crashlytics wrote:
This crash has non-main threads that appear to use UIKit classes or
functions. Generally speaking, it is only safe to use UIKit from the
main thread. Calling into UIKit from background threads can cause
unpredictable behavior (like crashes!). Please double check that all
of your code (that is not on the main thread) has been explicitly
marked as safe to use in the background by Apple.
But we don't use other threads in app.
Crashlytics logs:
Crashed: Thread 0 libobjc.A.dylib 0x184370910
objc_msgSend + 16 1 AVFoundation 0x18ad241bc
+[AVOutputContext(FigRoutingContext) currentRoutingContextFactory] + 56 2 AVFoundation 0x18ad1ee28
+[AVFigRoutingContextOutputContextImpl sharedAudioPresentationOutputContext] + 28 3 AVFoundation
0x18acb4a24 +[AVOutputContext sharedAudioPresentationOutputContext] +
40 4 MediaPlayer 0x1965cf1cc
-[MPAVLightweightRoutingController pickedRoutes] + 68 5 MediaPlayer 0x1965e8338 -[MPVolumeView _setShowsVolumeSlider:] + 96 6 MediaPlayer
0x1965e6ad4 -[MPVolumeView layoutSubviews] + 208 7 UIKit
0x18ed77770 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1420
8 QuartzCore 0x18931925c -[CALayer
layoutSublayers] + 184 9 QuartzCore 0x18931d3ec
CA::Layer::layout_if_needed(CA::Transaction*) + 324 10 QuartzCore
0x189289aa0 CA::Context::commit_transaction(CA::Transaction*) + 320 11
QuartzCore 0x1892b15d0 CA::Transaction::commit() +
580 12 QuartzCore 0x1892b1d10
CA::Transaction::release_thread(void*) + 244 13
libsystem_pthread.dylib 0x184dc857c _pthread_tsd_cleanup + 572
14 libsystem_pthread.dylib 0x184dc82cc _pthread_exit + 88 15
libsystem_pthread.dylib 0x184dc80d4 _pthread_wqthread + 1472 16
libsystem_pthread.dylib 0x184dc7b08 start_wqthread + 4
Init code:
self.volumeView = MPVolumeView.init(frame: CGRect.init(x: 0, y: 2,
width: 52.0,
height: 30.0))
self.volumeView?.showsVolumeSlider = false self.volumeView?.showsRouteButton = true
self.volumeView?.setRouteButtonImage(UIImage.init(named: "streaming_icon"), for: .normal)
self.volumeView?.setRouteButtonImage(UIImage.init(named: "selected_streaming_icon"), for: .selected)
self.volumeView.sizeToFit()
Please help resolve this issue.
I have contacted Apple and they have verified my theory that MPVolumeView performs UI layout changes on a background thread.
Bug report created.
Update 2018-05-30:
Engineering has determined that your bug report (40594280) is a duplicate of 39309134 and will be closed.
I have the same crash condition using MPVolumeView and AVPlayer.
With other weird things going on, like the volume slider disappearing.
The issues go away if I set the AVPlayer object attribute 'allowsExternalPlayback' to false.
player.allowsExternalPlayback = false
Seems strange but it worked.
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.
Many of my users get the crash describes in the below stack trace.
As you can read it seems to happen at the application launch and it does not involved any of our methods if we did not take into account the standard main call at line 28.
I do not know how to fix this bug as I do not manage to reproduce it and the below stack trace is not helpful for me.
The bug appears only on iOS9 (93% iOS9.2, 4% iOS 9.1.0, etc..)
Maybe someone know what to do in this case?
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x180911bd0 objc_msgSend + 16
1 Foundation 0x181b7b5f4 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 372
2 Foundation 0x181c2430c _NSSetPointValueAndNotify + 284
3 UIKit 0x18608e798 -[UIView(Geometry) _applyISEngineLayoutValues] + 656
4 UIKit 0x185f9b458 -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 136
5 CoreFoundation 0x181188370 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 132
6 CoreFoundation 0x181188268 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 308
7 UIKit 0x185f89f8c -[UIView(Geometry) resizeSubviewsWithOldSize:] + 148
8 UIKit 0x18608e8e0 -[UIView(AdditionalLayoutSupport) _is_layout] + 128
9 UIKit 0x1862931f0 -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 756
10 UIKit 0x185f7f778 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 656
11 QuartzCore 0x18398eb2c -[CALayer layoutSublayers] + 148
12 QuartzCore 0x183989738 CA::Layer::layout_if_needed(CA::Transaction*) + 292
13 QuartzCore 0x1839895f8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
14 QuartzCore 0x183988c94 CA::Context::commit_transaction(CA::Transaction*) + 252
15 QuartzCore 0x1839889dc CA::Transaction::commit() + 512
16 QuartzCore 0x1839820cc CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 80
17 CoreFoundation 0x181248588 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
18 CoreFoundation 0x18124632c __CFRunLoopDoObservers + 372
19 CoreFoundation 0x18124675c __CFRunLoopRun + 928
20 CoreFoundation 0x181175680 CFRunLoopRunSpecific + 384
21 GraphicsServices 0x182684088 GSEventRunModal + 180
22 UIKit 0x185fecd90 UIApplicationMain + 204
23 once 0x1000f0f00 main (main.m:14)
24 libdispatch.dylib 0x180d168b8 (Missing)
As an additional information I'm using AFNetworking. Here is the AFNetworking thread stack trace that does not crash:
Thread : AFNetworking
0 libsystem_kernel.dylib 0x180e194bc mach_msg_trap + 8
1 libsystem_kernel.dylib 0x180e19338 mach_msg + 72
2 CoreFoundation 0x181248ac0 __CFRunLoopServiceMachPort + 196
3 CoreFoundation 0x1812467c4 __CFRunLoopRun + 1032
4 CoreFoundation 0x181175680 CFRunLoopRunSpecific + 384
5 Foundation 0x181b6d21c -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 308
6 Foundation 0x181bc2874 -[NSRunLoop(NSRunLoop) run] + 88
7 once 0x1001ddf9c +[AFURLConnectionOperation networkRequestThreadEntryPoint:] (AFURLConnectionOperation.m:169)
8 Foundation 0x181c53c40 __NSThread__start__ + 1000
9 libsystem_pthread.dylib 0x180efbb28 _pthread_body + 156
Maybe it could help.
Thank you for your help!
I found another entry in SO with a stack that's eerily similar to yours. There was a resolution involving the removal of a setTranslatesAutoresizingMaskIntoConstraints:NO in a subview.
issue with reentering of view with [UIView(Geometry) _applyISEngineLayoutValues] in iOS8 but not iOS7
At application startup, this could only be your main view controller or the launchScreen if you have a xib/storyboard for it.
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.