My iOS App is crashing with the following error:
*** Assertion failure in -[FBSSerialQueue assertOnQueue], /BuildRoot/Library/Caches/com.apple.xbs/Sources/FrontBoardServices/FrontBoard-626.4.1/FrontBoardServices/FBSSerialQueue.m:98
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'threading violation: expected the main thread'
And this is the stacktrace:
Exception: NSInternalInconsistencyException
Reason: threading violation: expected the main thread
Stacktrace: (
0 CoreFoundation 0x000000018d56c980 DC2C95C6-B954-39E8-86A2-5E0AF8801E87 + 1255808
1 libobjc.A.dylib 0x000000018d285028 objc_exception_throw + 60
2 CoreFoundation 0x000000018d4694fc DC2C95C6-B954-39E8-86A2-5E0AF8801E87 + 193788
3 Foundation 0x000000018d8aa690 7A7A96AF-79E4-3DB1-8904-42E61CAE8999 + 571024
4 FrontBoardServices 0x00000001927ae7ec 370F1F18-E8A9-36B5-B0EB-9735A02CE2DE + 366572
5 FrontBoardServices 0x0000000192760460 370F1F18-E8A9-36B5-B0EB-9735A02CE2DE + 46176
6 FrontBoardServices 0x00000001927606ec 370F1F18-E8A9-36B5-B0EB-9735A02CE2DE + 46828
7 FrontBoardServices 0x00000001927605e4 370F1F18-E8A9-36B5-B0EB-9735A02CE2DE + 46564
8 UIKitCore 0x00000001911e1c40 AAFEFEBE-C172-3346-8972-810EB8F2F2C6 + 5995584
9 UIKitCore 0x00000001912d1870 AAFEFEBE-C172-3346-8972-810EB8F2F2C6 + 6977648
10 UIKitCore 0x00000001912d2640 AAFEFEBE-C172-3346-8972-810EB8F2F2C6 + 6981184
11 CameraUI 0x00000001afbb8514 289C074B-4FFE-3D83-927A-98B268DD914F + 652564
12 libobjc.A.dylib 0x000000018d29f3f8 objc_release + 136
13 CameraUI 0x00000001afc5b118 289C074B-4FFE-3D83-927A-98B268DD914F + 1319192
14 libobjc.A.dylib 0x000000018d284130 2C18C54E-6C84-310C-851F-F9602890D908 + 20784
15 libobjc.A.dylib 0x000000018d296f80 objc_destructInstance + 92
16 libobjc.A.dylib 0x000000018d29de44 _objc_rootDealloc + 52
17 CameraUI 0x00000001afc502c4 289C074B-4FFE-3D83-927A-98B268DD914F + 1274564
18 libobjc.A.dylib 0x000000018d29f3f8 objc_release + 136
19 CoreFoundation 0x000000018d4b243c DC2C95C6-B954-39E8-86A2-5E0AF8801E87 + 492604
20 CoreFoundation 0x000000018d43cfc0 DC2C95C6-B954-39E8-86A2-5E0AF8801E87 + 12224
21 libobjc.A.dylib 0x000000018d29f3f8 objc_release + 136
22 CameraUI 0x00000001afcb3704 289C074B-4FFE-3D83-927A-98B268DD914F + 1681156
23 libobjc.A.dylib 0x000000018d284130 2C18C54E-6C84-310C-851F-F9602890D908 + 20784
24 libobjc.A.dylib 0x000000018d296f80 objc_destructInstance + 92
25 libobjc.A.dylib 0x000000018d29de44 _objc_rootDealloc + 52
26 CameraUI 0x00000001afca48ac 289C074B-4FFE-3D83-927A-98B268DD914F + 1620140
27 libobjc.A.dylib 0x000000018d29f3f8 objc_release + 136
28 libsystem_blocks.dylib 0x000000018d18fa08 _Block_release + 168
29 libobjc.A.dylib 0x000000018d29f3f8 objc_release + 136
30 libsystem_blocks.dylib 0x000000018d18fa08 _Block_release + 168
31 libdispatch.dylib 0x0000000102d3b27c _dispatch_client_callout + 20
32 libdispatch.dylib 0x0000000102d4290c _dispatch_lane_serial_drain + 720
33 libdispatch.dylib 0x0000000102d434fc _dispatch_lane_invoke + 408
34 libdispatch.dylib 0x0000000102d4e4dc _dispatch_workloop_worker_thread + 1344
35 libsystem_pthread.dylib 0x000000018d2776d0 _pthread_wqthread + 280
36 libsystem_pthread.dylib 0x000000018d27d9e8 start_wqthread + 8
)
Is seems to be completely outside of my code. Is there any way to debug this? Is it a bug in an iOS component?
The UIImagePickerController seems to be involved. It seems to happen shortly after picking a foto via the camera.
EDIT: Here is what the debug navigator is showing right after the crash:
And one more screenshot:
I cannot identify a single action in the app that reproduces the crash. I need to click around in a component that takes a picture from the camera and saves it into a UICollectionView. Only sometimes and eventually, the crash happens at different points.
I've verified that the code inside imagePickerController:didFinishPickingMediaWithInfo: is running on the main thread.
How can I locate the exact place in my the code where this crash is happening?
EDIT 2: Update from Apple developer technical support; they believe that it is a bug and they suggest filing a bug report.
In iOS14 UIImagePicker is being deprecated, so I would suggest wrapping your code in an iOS version check and using the new PHPickerViewController instead. Not the best solutions, but it's something.
Related
For a crash in my application, NSDictionary is an attribute of the model, and when the model executes the cxx_destruct function, crash occurs inside the NSDictionary.There's a place in the crash stack that I'm not sure about cow_cleanup, what's going on in this function?
And The reason for the crash is that during the model release process, NSDictionary changed, right?
Here is the concrete Crash stack
Thread 0 Crashed:
0 libobjc.A.dylib objc_release + 16
1 CoreFoundation cow_cleanup + 168
2 CoreFoundation -[__NSDictionaryM dealloc] + 144
3 imeituan -[CKContent .cxx_destruct] (CKContent.m:12)
4 libobjc.A.dylib object_cxxDestructFromClass(objc_object*, objc_class*) + 112
5 libobjc.A.dylib objc_destructInstance + 88
6 libobjc.A.dylib _objc_rootDealloc + 52
7 imeituan -[CKTableViewCell .cxx_destruct] (CKTableViewCell.m:44)
8 libobjc.A.dylib object_cxxDestructFromClass(objc_object*, objc_class*) + 112
9 libobjc.A.dylib objc_destructInstance + 88
10 libobjc.A.dylib _objc_rootDealloc + 52
11 UIKitCore -[UIResponder dealloc] + 152
12 UIKitCore -[UIView dealloc] + 872
13 UIKitCore -[UITableViewCell dealloc] + 236
14 imeituan -[CKBubbleCell dealloc (CKBubbleCell.m:222)
15 CoreFoundation -[__NSArrayM dealloc] + 228
16 UIKitCore -[UITableView .cxx_destruct] + 1524
17 libobjc.A.dylib object_cxxDestructFromClass(objc_object*, objc_class*) + 112
18 libobjc.A.dylib objc_destructInstance + 88
19 libobjc.A.dylib _objc_rootDealloc + 52
20 UIKitCore -[UIResponder dealloc] + 152
21 UIKitCore -[UIView dealloc] + 872
22 UIKitCore -[UIScrollView dealloc] + 852
23 UIKitCore -[UITableView dealloc] + 364
24 UIKitCore __destroy_helper_block_e8_32s40s + 24
25 libsystem_blocks.dylib _Block_release + 148
26 Foundation -[_NSTimerBlockTarget dealloc] + 44
27 Foundation _timerRelease + 64
28 CoreFoundation __CFRunLoopDoTimer + 936
29 CoreFoundation __CFRunLoopDoTimers + 276
30 CoreFoundation __CFRunLoopRun + 1640
31 CoreFoundation CFRunLoopRunSpecific + 424
32 GraphicsServices GSEventRunModal + 160
33 UIKitCore UIApplicationMain + 1932
34 imeituan main (main.m:38)
35 libdyld.dylib start + 4
Crashes like this are really tricky. The key to keep in mind is that you are crashing during a deallocation. And, more specifically, the crashing function is objc_release. To me, this strongly indicates that you've got an over-released object. It's looks to me like one of your model objects may have already been freed by this point. The issue isn't with the dictionary, directly.
I'd recommend using NSZombies, or one of the other memory allocation tools within Instruments to try to track down where your memory-management issue is.
Our app is crash online, not in debug mode.
We cannot reproduce the crash.
Here is the crash log which caught with bugly.
Anyone could help or some clue , Please!
#43 Thread
SIGSEGV
SEGV_ACCERR
0 libobjc.A.dylib objc_msgSend + 16
1 CoreFoundation ___CFPropertyListIsValidAux + 56
2 CoreFoundation ___CFPropertyListIsDictPlistAux + 188
3 CoreFoundation ___CFDictionaryApplyFunction_block_invoke + 24
4 CoreFoundation _CFBasicHashApply + 132
5 CoreFoundation CFDictionaryApplyFunction + 180
6 CoreFoundation ___CFPropertyListIsValidAux + 388
7 CoreFoundation CFPropertyListIsValid + 28
8 CFNetwork ___ZN12__CFURLCache23CreateAndStoreCacheNodeEP16__CFURLCacheNodePK20_CFCachedURLResponsePK10__CFStringPK13_CFURLRequestPKvbRb_block_invoke + 148
9 libdispatch.dylib __dispatch_call_block_and_release + 24
10 libdispatch.dylib __dispatch_client_callout + 16
11 libdispatch.dylib __dispatch_lane_serial_drain$VARIANT$mp + 592
12 libdispatch.dylib __dispatch_lane_invoke$VARIANT$mp + 432
13 libdispatch.dylib __dispatch_workloop_worker_thread + 600
14 libsystem_pthread.dylib _pthread_wqthread + 312
My app is experiencing a weird error which I cannot reproduce. I know the existence of this error because some users have reported it to me and I could catch it using the Fabric SDK.
Apparently it happens at any location, at any given time. It doesn't not happen a lot though, it seems to happen once in a while. I have no idea where to start looking for this, because I tried to catch the error running on multiple devices connected to my xcode project, but it just doesn't happen to me, or at least when I am looking for it. Can someone give me a light where to begin to look for it?
The stack trace:
Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x18730afe0 __exceptionPreprocess
1 libobjc.A.dylib 0x185d6c538 objc_exception_throw
2 CoreFoundation 0x187311ef4 __methodDescriptionForSelector
3 CoreFoundation 0x18730ef54 ___forwarding___
4 CoreFoundation 0x18720ad4c _CF_forwarding_prep_0
5 Foundation 0x187dff50c __NSThreadPerformPerform
6 CoreFoundation 0x1872b942c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
7 CoreFoundation 0x1872b8d04 __CFRunLoopDoSources0
8 CoreFoundation 0x1872b69a8 __CFRunLoopRun
9 CoreFoundation 0x1871e6da4 CFRunLoopRunSpecific
10 GraphicsServices 0x188c51074 GSEventRunModal
11 UIKit 0x18d49ac9c UIApplicationMain
12 Otelo 0x100230fc4 main (AppDelegate.swift:23)
13 libdyld.dylib 0x1861f559c start
Crashed: com.twitter.crashlytics.ios.exception
0 Otelo 0x1005bb308 CLSProcessRecordAllThreads + 1572
1 Otelo 0x1005bb308 CLSProcessRecordAllThreads + 1572
2 Otelo 0x1005bb1c4 CLSProcessRecordAllThreads + 1248
3 Otelo 0x1005aaa6c CLSHandler + 48
4 Otelo 0x1005b9110 __CLSExceptionRecord_block_invoke + 92
5 libdispatch.dylib 0x1861c29a0 _dispatch_client_callout + 16
6 libdispatch.dylib 0x1861cfee0 _dispatch_barrier_sync_f_invoke + 84
7 Otelo 0x1005b8ba4 CLSExceptionRecord + 212
8 Otelo 0x1005b89cc CLSExceptionRecordNSException + 548
9 Otelo 0x1005b85e0 CLSTerminateHandler() + 396
10 libc++abi.dylib 0x185d5b5d4 std::__terminate(void (*)()) + 16
11 libc++abi.dylib 0x185d5b1a8 __cxa_rethrow + 144
12 libobjc.A.dylib 0x185d6c6f8 objc_exception_rethrow + 44
13 CoreFoundation 0x1871e6e10 CFRunLoopRunSpecific + 532
14 GraphicsServices 0x188c51074 GSEventRunModal + 100
15 UIKit 0x18d49ac9c UIApplicationMain + 208
16 Otelo 0x100230fc4 main (AppDelegate.swift:23)
17 libdyld.dylib 0x1861f559c start + 4
I got a crash from Fabric,the stack is below:
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 6806634868 objc_release + 20
1 libsystem_blocks.dylib 6813456656 _Block_release + 256
2 libobjc.A.dylib 6806640420 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 564
3 CoreFoundation 6529519172 _CFAutoreleasePoolPop + 28
4 UIKit 6605817924 _wrapRunLoopWithAutoreleasePoolHandler + 76
5 CoreFoundation 6530394704 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
6 CoreFoundation 6530382300 __CFRunLoopDoObservers + 360
7 CoreFoundation 6530383292 __CFRunLoopRun + 836
8 CoreFoundation 6529519780 CFRunLoopRunSpecific + 396
9 GraphicsServices 6682260900 GSEventRunModal + 168
10 UIKit 6606283712 UIApplicationMain + 1488
11 Spec 4297532060 main (main.m:15)
12 libdyld.dylib 6813280776 start + 4
I don't know why it would be _Block_release after (anonymous namespace)::AutoreleasePoolPage::pop(void*). Is it possible that a block was added to autoreleasepool?if possible, why the block crashed at release and it not crashed at invoke?
Ok,I had resolve this bug.The reason for the crash was that I had hook the function objectAtIndex for NSMutableArray.And If user switch from background,the app would get a crash -[UIKeyboardLayoutStar release]: message sent to deallocated.
So remove the hook code will resolve this bug.
App crashes if photo access permission is not granted and the object which asked for permission is about to deallocate.
Apple's sample code (for Photos framework) crashes too.
My app crashes with following stack trace:
*** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'This application is not allowed to access Photo data.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010a324f65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010c030deb objc_exception_throw + 48
2 PhotoLibraryServices 0x000000011c1f7e2d -[PLPhotoLibrary initWithTransientContext:name:] + 1183
3 Photos 0x000000011bd6a445 __30-[PHPhotoLibrary photoLibrary]_block_invoke + 59
4 libdispatch.dylib 0x0000000110f5e49b _dispatch_client_callout + 8
5 libdispatch.dylib 0x0000000110f49e28 dispatch_once_f + 543
6 Photos 0x000000011bd6a404 -[PHPhotoLibrary photoLibrary] + 140
7 Photos 0x000000011bd3e5e8 -[PHCoreImageManager _cancelAndFlushPreheatItemsForAssets:CPLPrefetching:domain:operation:passingTestHandler:didCancelHandler:] + 174
8 Photos 0x000000011bd5900c -[PHImageManager dealloc] + 176
9 libobjc.A.dylib 0x000000010c044afe _ZN11objc_object17sidetable_releaseEb + 232
10 MyApp 0x000000010f271812 _TToFC12MyApp16PhotosDataSourceE + 66
11 libobjc.A.dylib 0x000000010c02f7bb _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 127
12 libobjc.A.dylib 0x000000010c03a390 objc_destructInstance + 93
13 libobjc.A.dylib 0x000000010c03a3c3 object_dispose + 22
14 MyApp 0x000000010f271796 _TFC12MyApp16PhotosDataSourceD + 198
15 MyApp 0x000000010f2717c2 _TToFC12MyApp16PhotosDataSourceD + 34
16 libobjc.A.dylib 0x000000010c044afe _ZN11objc_object17sidetable_releaseEb + 232
17 MyApp 0x000000010f2668f2 _TToFC12MyApp25PhotoPickerViewControllerE + 178
18 libobjc.A.dylib 0x000000010c02f7bb _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 127
19 libobjc.A.dylib 0x000000010c03a390 objc_destructInstance + 93
20 libobjc.A.dylib 0x000000010c03a3c3 object_dispose + 22
21 UIKit 0x000000010adb54b9 -[UIResponder dealloc] + 130
22 UIKit 0x000000010ad40721 -[UIViewController dealloc] + 1949
23 UIKit 0x000000010ad1c97b -[UIPresentationController .cxx_destruct] + 262
24 libobjc.A.dylib 0x000000010c02f7bb _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 127
25 libobjc.A.dylib 0x000000010c03a390 objc_destructInstance + 93
26 libobjc.A.dylib 0x000000010c03a3c3 object_dispose + 22
27 UIKit 0x000000010ad185db -[UIPresentationController dealloc] + 56
28 UIKit 0x000000010b4a9046 -[_UIFullscreenPresentationController dealloc] + 56
29 libobjc.A.dylib 0x000000010c044afe _ZN11objc_object17sidetable_releaseEb + 232
30 UIKit 0x000000010ad1838c __destroy_helper_block_411 + 24
31 libsystem_blocks.dylib 0x0000000110fdb6b1 _Block_release + 128
32 UIKit 0x000000010b568d9c -[_UIViewControllerTransitionContext .cxx_destruct] + 94
33 libobjc.A.dylib 0x000000010c02f7bb _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 127
34 libobjc.A.dylib 0x000000010c03a390 objc_destructInstance + 93
35 libobjc.A.dylib 0x000000010c03a3c3 object_dispose + 22
36 UIKit 0x000000010b567825 -[_UIViewControllerTransitionContext dealloc] + 56
37 UIKit 0x000000010b568e51 -[_UIViewControllerOneToOneTransitionContext dealloc] + 79
38 libobjc.A.dylib 0x000000010c044afe _ZN11objc_object17sidetable_releaseEb + 232
39 MyApp 0x000000010d4818d2 block_destroy_helper + 66
40 MyApp 0x000000010d481988 _TPA__TFFC16MyApp31CustomShrinkAnimator17animateTransitionFS0_FPSo36UIViewControllerContextTransitioning_T_U0_FSbT_ + 152
41 MyApp 0x000000010d481a28 _TPA__TTRXFo_dSb_dT__XFo_iSb_iT__ + 120
42 MyApp 0x000000010d481aed block_destroy_helper8 + 13
43 libsystem_blocks.dylib 0x0000000110fdb6b1 _Block_release + 128
44 UIKit 0x000000010ac5ee47 -[UIViewAnimationBlockDelegate .cxx_destruct] + 43
45 libobjc.A.dylib 0x000000010c02f7bb _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 127
46 libobjc.A.dylib 0x000000010c03a390 objc_destructInstance + 93
47 libobjc.A.dylib 0x000000010c03a3c3 object_dispose + 22
48 libobjc.A.dylib 0x000000010c044afe _ZN11objc_object17sidetable_releaseEb + 232
49 CoreFoundation 0x000000010a228d4d -[__NSDictionaryI dealloc] + 141
50 libobjc.A.dylib 0x000000010c044afe _ZN11objc_object17sidetable_releaseEb + 232
51 libobjc.A.dylib 0x000000010c0450b8 _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 488
52 CoreFoundation 0x000000010a2129c6 _CFAutoreleasePoolPop + 22
53 CoreFoundation 0x000000010a246941 __CFRunLoopRun + 2081
54 CoreFoundation 0x000000010a245e98 CFRunLoopRunSpecific + 488
55 GraphicsServices 0x0000000112598ad2 GSEventRunModal + 161
56 UIKit 0x000000010abb8676 UIApplicationMain + 171
57 MyApp 0x00000001082b470d main + 109
58 libdyld.dylib 0x0000000110f9392d start + 1
59 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Any pointers would be really appreciated.
This is expected behaviour.
Before you use any methods (like fetching, changing) of the Photos Framework, check the permission status to the Photo-Library. This is done by calling the authorizationStatus method of PHPhotoLibrary. If this method PHAuthorizationStatusNotDetermined,ask for permission using the requestAuthorization method. If authorizationStatushas a value of PHAuthorizationStatusDenied fall gracefully.
The main point is to let requestAuthorization prompt for access to the Photo-Library and not the fetch methods directly.
My crash situation is using PHCachingImageManager as a property.
fileprivate let imageManager = PHCachingImageManager()
I fix it by changing it to lazy var :
fileprivate lazy var imageManager = PHCachingImageManager()
I had the same experience. However, to reproduce it was not enough to exit the view controller and have it deallocated, but to Simulate Memory Warning in the simulator. This forced the crash.
So, my solution was to not use PHImageManager as a global variable, but to access it when need. Instead of this:
private let imageManager = PHImageManager.defaultManager()
...
imageManager.requestImageForAsset(....)
I did like this when needed:
PHImageManager.defaultManager().requestImageForAsset(....)
PHImageManager add a dispatch source event DISPATCH_SOURCE_TYPE_MEMORYPRESSURE when init.
When receive memory warning Photos framework will try to remove cached data in this event handler. At that time, if you have call but not get the authorization, it will cause crash
cause crash
For me it was crashing on 11 & 12 versions if user is not giving permissions to photos, but working fine on iOS 13. Below line was causing the issue.
fileprivate var imageManager = PHImageManager() // Crash
fileprivate lazy var imageManager = PHImageManager() // fixed the crash.