I use AVPlayer to play remote videos in Swift, but keep getting these crashes showing up
#0
Crashed: com.apple.avfoundation.playerlayer.configuration
EXC_BREAKPOINT 0x000000010522f968
0 libswiftCore.dylib
__hidden#23281_ line 134
specialized _assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never
1
libswiftFoundation.dylib
swift_stdlib_bridgeNSErrorToError + 59336
2 libswiftFoundation.dylib
swift_convertStringToNSString + 559540
3
libswiftFoundation.dylib
swift_stdlib_bridgeNSErrorToError + 61096
4 Foundation
-[NSKeyValueUnnestedProperty _givenPropertiesBeingInitialized:getAffectingProperties:] + 200
5
Foundation
-[NSKeyValueUnnestedProperty _initWithContainerClass:key:propertiesBeingInitialized:] + 152
6 Foundation
NSKeyValuePropertyForIsaAndKeyPathInner + 284
7 Foundation
NSKeyValuePropertyForIsaAndKeyPath + 144
8 Foundation
-[NSObject(NSKeyValueObserverRegistration) addObserver:forKeyPath:options:context:] + 92
9 AVFoundation
-[AVPlayerItem addObserver:forKeyPath:options:context:] + 368
10 AVFoundation
-[AVKVODispatcher startObservingValueAtKeyPath:ofObject:options:usingBlock:] + 136
11 AVFoundation
-[AVKeyPathDependency _startObservingSecondLevelPropertyOnNewCurrentValueForTopLevelDependencyProperty:] + 132
12 AVFoundation
-[AVKeyPathDependencyManager dependencyHostIsFullyInitialized] + 236
13 AVFoundation
-[AVKeyPathFlattener initForObservingValueAtKeyPath:onObject:] + 188
14 AVFoundation
-[AVKVODispatcher startObservingValueAtTwoPartKeyPath:ofObject:options:usingBlock:] + 100
15 AVFoundation
-[AVKVODispatcher(LegacyCallbackMethod) startObservingObject:weakObserver:forTwoPartKeyPath:options:context:] + 152
16 AVFoundation
-[AVPlayerLayer _startObservingPlayer:] + 404
17 libdispatch.dylib
_dispatch_call_block_and_release + 24
18 libdispatch.dylib
_dispatch_client_callout + 16
19 libdispatch.dylib
_dispatch_queue_serial_drain$VARIANT$mp + 528
20 libdispatch.dylib
_dispatch_queue_invoke$VARIANT$mp + 340
21 libdispatch.dylib
_dispatch_root_queue_drain_deferred_wlh$VARIANT$mp + 404
22 libdispatch.dylib
_dispatch_workloop_worker_thread$VARIANT$mp + 644
23 libsystem_pthread.dylib
_pthread_wqthread + 932
24
libsystem_pthread.dylib
start_wqthread + 4
I've used traditional KVO by adding an observer to self and overriding the observeValueForKey function and also tried using the new block-based KVO, but something along the lines of this crash always happens (and yes I always remove observers on deinit). This mostly happens on ios 11 devices but I've never gotten this crash on my own device, so I have no idea how it happens.
Does anyone have any idea why this happens or things I can try to fix it? The crash rate on this keeps going up as I add more videos into the app.
Related
My app works well the 99% of times but 1% it's crashing after opening the camera, we are getting a random crash. This is the stacktrace from Crashlytics:
Crashed: com.apple.camera.avcapturesession
0 libobjc.A.dylib 0x194d8fbd0 objc_msgSend + 16
1 UIKit 0x1890df21c -[UIViewAnimationState animationForLayer:forKey:forView:] + 712
2 UIKit 0x188e55724 -[UIViewAnimationState actionForLayer:forKey:forView:] + 44
3 UIKit 0x188e19f44 -[UIView(CALayerDelegate) actionForLayer:forKey:] + 140
4 QuartzCore 0x188774e88 -[CALayer actionForKey:] + 104
5 QuartzCore 0x18876a86c actionForKey(CALayer*, CA::Transaction*, NSString*) + 100
6 QuartzCore 0x18876a6d8 CA::Layer::begin_change(CA::Transaction*, unsigned int, objc_object*&) + 176
7 QuartzCore 0x18876d6a0 CA::Layer::setter(unsigned int, _CAValueType, void const*) + 156
8 QuartzCore 0x188774e14 -[CALayer setOpacity:] + 48
9 UIKit 0x188e19a5c -[UIView(Rendering) setAlpha:] + 104
10 corporate 0x1005a3e5c -[GSDK_GTMReadMonitorInputStream .cxx_destruct]
11 corporate 0x1005a4398 -[GSDK_GTMReadMonitorInputStream .cxx_destruct]
12 CoreFoundation 0x184614ae4 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
13 CoreFoundation 0x184553220 _CFXNotificationPost + 2060
14 Foundation 0x185452cc0 -[NSNotificationCenter postNotificationName:object:userInfo:] + 72
15 AVFoundation 0x182efd9c4 -[AVCaptureSession _setRunning:] + 312
16 CameraKit 0x18aac1adc __38-[CAMCaptureController _startPreview:]_block_invoke829
17 libdispatch.dylib 0x1953c13ac _dispatch_call_block_and_release + 24
18 libdispatch.dylib 0x1953c136c _dispatch_client_callout + 16
19 libdispatch.dylib 0x1953cb4c0 _dispatch_queue_drain + 1216
20 libdispatch.dylib 0x1953c4474 _dispatch_queue_invoke + 132
21 libdispatch.dylib 0x1953cd224 _dispatch_root_queue_drain + 664
22 libdispatch.dylib 0x1953ce75c _dispatch_worker_thread3 + 108
23 libsystem_pthread.dylib 0x19559d2e4 _pthread_wqthread + 816
24 libsystem_pthread.dylib 0x19559cfa8 start_wqthread + 4
I don't fully understand where this crash is coming from but I found that I could be related to GoogleNetworkingUtilities.
try this
Are you certain that you aren't doing anything that would effect any UI elements in a background thread?
If you're on iOS 10 you need to add Privacy - Camera Usage Description to your Info.plist file
I started getting this warning :
This application is modifying the autolayout engine from a background
thread, which can lead to engine corruption and weird crashes. This
will cause an exception in a future release.
Here is the backtrace with the warning message :
Stack:(
0 CoreFoundation 0x25542303 <redacted> + 150
1 libobjc.A.dylib 0x24d0edff objc_exception_throw + 38
2 CoreFoundation 0x25542231 <redacted> + 0
3 Foundation 0x25e25bbb <redacted> + 170
4 Foundation 0x25ccb637 <redacted> + 38
5 UIKit 0x297e0431 <redacted> + 52
6 UIKit 0x297e0e1f <redacted> + 222
7 UIKit 0x297fd52d <redacted> + 96
8 UIKit 0x29efe579 <redacted> + 320
9 UIKit 0x299dc8e9 <redacted> + 148
10 UIKit 0x299cb44f <redacted> + 42
11 UIKit 0x296d5a83 <redacted> + 714
12 QuartzCore 0x277b1ad5 <redacted> + 128
13 QuartzCore 0x277ad1d1 <redacted> + 352
14 QuartzCore 0x277ad061 <redacted> + 16
15 QuartzCore 0x277ac581 <redacted> + 368
16 QuartzCore 0x277ac233 <redacted> + 614
17 QuartzCore 0x277d9b63 <redacted> + 310
18 libsystem_pthread.dylib 0x25279905 <redacted> + 508
19 libsystem_pthread.dylib 0x25279507 <redacted> + 86
20 libsystem_pthread.dylib 0x2527a485 pthread_exit + 28
21 Foundation 0x25ca31d7 <redacted> + 10
22 Foundation 0x25d5e34f <redacted> + 1178
23 libsystem_pthread.dylib 0x2527ac7f <redacted> + 138
24 libsystem_pthread.dylib 0x2527abf3 _pthread_start + 110
25 libsystem_pthread.dylib 0x25278a08 thread_start + 8
As far as i know i don't use Autolayout (as i want the app to be iOS 5.1.1 compatible). and also i don't seem to be within the reported backtrace.
I also have the PSPDFUIKitMainThreadGuard class enabled, which should be checking the main thread accesses but nothing trigered out of this thing.
Is there any way how to find out what is doing such a thing?
Question This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes doesn't explain how to debug such thing.
Whether or not you are using Autolayout directly is not the issue at hand. The OS is converting legacy autoresizingMask to modern NSLayoutConstraint under the hood.
The issue has to do with modifying the UI from anywhere but the main tread.
This typically happens when:
responding to a NSNotification
returning from an async method
executing a completion block on a thread you do not control
explicitly scheduling a task in the background
Note about The app doesn't crash...
The app will crash. All you need is time and a few thousand users...
I have been getting crash reports like this for a keyboard extension I have developed and am either confused about how to read the stack trace or why it is occurring or both and I was hoping someone could help me clear this up.
Below is the stack trace:
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0xd15db9df
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x37949f66 objc_msgSend + 5
1 UIKit 0x2cd57f05 -[_UIViewControllerTransitionContext completeTransition:] + 52
2 UIKit 0x2d10ac1f __95-[_UIWindowAnimationController _performLayoutAnimationWithContext:windowGeometryUpdatingBlock:]_block_invoke88 + 26
3 UIKit 0x2cc7b8e1 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 308
4 UIKit 0x2cc7b4f9 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 184
5 UIKit 0x2cc7b40f -[UIViewAnimationState animationDidStop:finished:] + 70
6 QuartzCore 0x2c660fe7 CA::Layer::run_animation_callbacks(void*) + 234
7 libdispatch.dylib 0x37ecdc6f _dispatch_client_callout + 22
8 libdispatch.dylib 0x37ed9553 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1322
9 CoreFoundation 0x295ac889 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
10 CoreFoundation 0x295aafa9 __CFRunLoopRun + 1512
11 CoreFoundation 0x294f69a1 CFRunLoopRunSpecific + 476
12 CoreFoundation 0x294f67b3 CFRunLoopRunInMode + 106
13 GraphicsServices 0x30e911a9 GSEventRunModal + 136
14 UIKit 0x2cca7635 UIApplicationMain + 1440
15 libxpc.dylib 0x3806f9e3 _xpc_objc_main + 706
16 libxpc.dylib 0x38071009 xpc_main + 168
17 Foundation 0x2a3ec289 service_connection_handler + 162
18 PlugInKit 0x32c5ff75 -[PKService run] + 508
19 PlugInKit 0x32c5fc4b +[PKService main] + 58
20 PlugInKit 0x32c5ffa9 +[PKService _defaultRun:arguments:] + 20
21 libextension.dylib 0x371b60c5 NSExtensionMain + 48
22 libdyld.dylib 0x37f0baaf start + 2
In the left column where it lists the libraries (correct term?) I don't see any reference to my code. In other crash logs there is always some reference to a class in my app or something but I don't see that in this one. What does that mean? Is the crash occurring before my code executes and this is an Apple issue I can ignore?
It's an Apple Bug. The keyboard extension I work on has a nearly identical crash report. Fortunately, this only seems to happen on iOS 8, though I have seen a similar one that affects iOS 9.
I would file a bug report with Apple, and include a copy of the stack trace.
Getting a lot of crash reports with this stack trace... unable to fix it.
Had suspicion that it has something to do with me manipulating cookies in the shared instance of NSHTTPCookieStorage, so i have added code to do it on the same thread, but I'm still expiring this.
Any thoughts or ideas will be much appreciated.
Thread 4 Crashed:
0 CoreFoundation 0x23363dc4 CFURLCopyAbsoluteURL + 60
1 CFNetwork 0x22e87039 HTTPCookieStorage::copyCookiesForURL(__CFURL const*, unsigned char) + 74
2 CFNetwork 0x22f65ed1 -[NSHTTPCookieStorage cookiesForURL:] + 90
3 CFNetwork 0x22eef4e1 -[__NSURLBackgroundSession requestWithCookiesApplied:] + 218
4 CFNetwork 0x22ef0505 -[__NSURLBackgroundSession _onqueue_uploadTaskForRequest:uploadFile:bodyData:completion:] + 126
5 CFNetwork 0x22ef03e5 __80-[__NSURLBackgroundSession uploadTaskForRequest:uploadFile:bodyData:completion:]_block_invoke + 38
6 CFNetwork 0x22eefadf __68-[__NSURLBackgroundSession performBlockOnQueueAndRethrowExceptions:]_block_invoke + 84
7 libdispatch.dylib 0x31577c6f _dispatch_client_callout + 20
8 libdispatch.dylib 0x31581559 _dispatch_barrier_sync_f_invoke + 46
9 CFNetwork 0x22eefa0f -[__NSURLBackgroundSession performBlockOnQueueAndRethrowExceptions:] + 208
10 CFNetwork 0x22ef0365 -[__NSURLBackgroundSession uploadTaskForRequest:uploadFile:bodyData:completion:] + 218
11 CFNetwork 0x22f497b7 -[NSURLSession uploadTaskWithRequest:fromFile:] + 32
12 Pogoplug 0x001a3ca5 __46-[CENetworkManager uploadRequest:finishBlock:]_block_invoke (CENetworkManager.m:377)
13 Foundation 0x2414abfd __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 6
14 Foundation 0x240b5ac5 -[NSBlockOperation main] + 146
15 Foundation 0x240a8505 -[__NSOperationInternal _start:] + 766
16 Foundation 0x2414d557 __NSOQSchedule_f + 184
17 libdispatch.dylib 0x315824d3 _dispatch_queue_drain$VARIANT$mp + 1460
18 libdispatch.dylib 0x31581da1 _dispatch_queue_invoke$VARIANT$mp + 82
19 libdispatch.dylib 0x31584491 _dispatch_root_queue_drain + 386
20 libdispatch.dylib 0x315858a3 _dispatch_worker_thread3 + 104
21 libsystem_pthread.dylib 0x316f8da9 _pthread_wqthread + 666
22 libsystem_pthread.dylib 0x316f8afc start_wqthread + 6
Finally found the cause after I managed to reproduce this issue while debugging, and its so silly on my part - its happening when url == nil for upload request.
Not sure why Apple allow to create NSURLMutableRequest with url == nil though, and not throwing exception in [NSMutableURLRequest requestWithURL:] method.
I would suggest check once with Instruments Tool, you will have a clear picture why and where exactly it is crashing.
I'm experiencing multiple crashes where it appears that a native iOS method is calling functions from a third-party library. Here's an example:
Thread: Unknown Name (Crashed)
0 libsystem_kernel.dylib 0x33222350 __pthread_kill + 8 + 8
1 libsystem_c.dylib 0x3500f973 abort + 95 + 94
2 libsystem_c.dylib 0x34ff04d1 basename + 1
3 FireChat 0x00036489 -[OTOverlayButton drawRect:] + 1
4 Foundation 0x37a4a5a9 -[NSDictionary(NSKeyValueCoding) valueForKey:] + 33 + 32
5 FireChat 0x709d -[NetworkModel getUserForUid:] (NetworkModel.m:150)
6 FireChat 0x0001c42f -[OpenTokController session:didReceiveStream:] (OpenTokController.m:258)
7 libdispatch.dylib 0x32da011f _dispatch_call_block_and_release + 11 + 10
8 libdispatch.dylib 0x32d9f4b7 _dispatch_client_callout + 23 + 22
9 libdispatch.dylib 0x32da41bd _dispatch_main_queue_callback_4CF$VARIANT$mp + 225 + 224
10 CoreFoundation 0x37dbbf3b __CFRunLoopRun + 1291 + 1290
11 CoreFoundation 0x37d2eebd CFRunLoopRunSpecific + 357 + 356
12 CoreFoundation 0x37d2ed49 CFRunLoopRunInMode + 105 + 104
13 GraphicsServices 0x358e22eb GSEventRunModal + 75 + 74
14 UIKit 0x3a1b42f9 UIApplicationMain + 1121 + 1120
15 FireChat 0x43b3 main (main.m:8)
To me, it appears that the [NSDictionary valueForKey:] method is invoking [OTOverlayButton drawRect:] which comes from a third-party library. This shouldn't be possible -- am I reading the crash report wrong?
[OTOverlayButton drawRect:] isn't called anywhere in my code. Note that the dictionary contains (my) objects which contain pointers to objects from the third-party library.
The library vendor and I are both baffled.
Thanks.
I believe the cause of this crash was memory corruption resulting from calling performSelector: on a method that returned a struct. See this blog post for more details:
Why performSelector is more dangerous than I thought