I have an property:
#property (nonatomic, retain) QBChatDialog* dialog;
When i make it nil in viewWillDisappear, it giving me error
- (void)viewWillDisappear:(BOOL)animated {
self.dialog = nil;
}
I am getting following error:
-[__NSArrayM removeObjectAtIndex:]: index 2147483647 beyond bounds for empty array'
even i don't use "removeObjectAtIndex". I think this is calling somewhere internally.
How to trace this.
my Complete Stack trace is:
(
0 CoreFoundation 0x05504494 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x05cd6e02 objc_exception_throw + 50
2 CoreFoundation 0x0540b2cd -[__NSArrayM removeObjectAtIndex:] + 445
3 Qboy 0x0026d23e -[TWMessageBarViewController statusBarHidden] + 43262
4 Qboy 0x002acffc QBAFQueryStringPairsFromKeyAndValue + 110104
5 libobjc.A.dylib 0x05cea060 _ZN11objc_object17sidetable_releaseEb + 238
6 libobjc.A.dylib 0x05ce9361 objc_release + 65
7 libobjc.A.dylib 0x05ce9318 objc_storeStrong + 39
8 Qboy 0x0007a35a -[ChatVC .cxx_destruct] + 298
9 libobjc.A.dylib 0x05cd58e2 _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 116
10 libobjc.A.dylib 0x05cd5869 object_cxxDestruct + 20
11 libobjc.A.dylib 0x05cdfcb6 objc_destructInstance + 48
12 CoreFoundation 0x0550e57c -[NSObject(NSObject) __dealloc_zombie] + 156
13 UIKit 0x038de904 -[UIResponder dealloc] + 162
14 UIKit 0x03855e85 -[UIViewController dealloc] + 2296
15 Qboy 0x0017bf93 -[QMChatViewController dealloc] + 835
16 UIKit 0x040c1b75 -[UIViewController(UIKitManual) release] + 88
17 libobjc.A.dylib 0x05ce934f objc_release + 47
18 libobjc.A.dylib 0x05cea52d _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 371
19 CoreFoundation 0x053d48a8 _CFAutoreleasePoolPop + 24
20 CoreFoundation 0x0540c43c __CFRunLoopRun + 2364
21 CoreFoundation 0x0540b846 CFRunLoopRunSpecific + 470
22 CoreFoundation 0x0540b65b CFRunLoopRunInMode + 123
23 GraphicsServices 0x06eef664 GSEventRunModal + 192
24 GraphicsServices 0x06eef4a1 GSEventRun + 104
25 UIKit 0x03688eb9 UIApplicationMain + 160
26 Qboy 0x000db84a main + 138
27 libdyld.dylib 0x062cca25 start + 1
28 ??? 0x00000001 0x0 + 1
)
Please suggest me. What to do?
error tells you that
you have an array which is empty/nil
and after that you are removing an item of object which object is no longer exists in this array
Trick: for quick fix search 'removeObjectAtIndex' all overs the project(from upper left 3rd search button). if find one/lot observe those
You may not be calling removeObjectAtIndex: inside viewWillDisappear:, but you are calling it within -[TWMessageBarViewController statusBarHidden]. Look there and I think you'll find the source of your crash!
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.
I have a problem with an app crashing for a few users, I have no idea whats causing it and all I got is this stacktrace from crashlytics:
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x0000000194e5016c objc_release + 12
1 learnchinese 0x00000001000a95a0 -[WGRLanguageLabel .cxx_destruct] (WGRLanguageLabel.m:34)
2 libobjc.A.dylib 0x0000000194e36b1c object_cxxDestructFromClass(objc_object*, objc_class*) + 148
3 libobjc.A.dylib 0x0000000194e43f38 objc_destructInstance + 92
4 libobjc.A.dylib 0x0000000194e43f90 object_dispose + 28
5 UIKit 0x0000000187f8771c -[UIResponder dealloc] + 116
6 UIKit 0x0000000187c3dc38 -[UIView dealloc] + 1000
7 learnchinese 0x00000001000a5460 -[WGRLanguageLabel dealloc] (WGRLanguageLabel.m:39)
8 CoreFoundation 0x00000001830a10f8 CFRelease + 524
9 CoreFoundation 0x00000001830ad6b8 -[__NSArrayM dealloc] + 152
10 libobjc.A.dylib 0x0000000194e51724 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 564
11 CoreFoundation 0x00000001830a4d14 _CFAutoreleasePoolPop + 28
12 UIKit 0x0000000187c34584 _wrapRunLoopWithAutoreleasePoolHandler + 76
13 CoreFoundation 0x000000018317bff0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
14 CoreFoundation 0x0000000183178f7c __CFRunLoopDoObservers + 360
15 CoreFoundation 0x000000018317935c __CFRunLoopRun + 836
16 CoreFoundation 0x00000001830a4f74 CFRunLoopRunSpecific + 396
17 GraphicsServices 0x000000018cb076fc GSEventRunModal + 168
18 UIKit 0x0000000187ca6d94 UIApplicationMain + 1488
19 learnchinese 0x00000001001679ec main (main.m:13)
20 libdyld.dylib 0x00000001954e2a08 start + 4
It looks like WGRLanguageLabel has been released when auto release pool try to release it again.
Here is the dealloc method in WGRLanguageLabel:
#implementation WGRLanguageLabel
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
...
#end
I'm seeing crashlogs being generated containing the following call stack
Thread : Crashed: com.apple.main-thread
0 libsystem_kernel.dylib 0x38a0a1f0 __pthread_kill + 8
1 libsystem_pthread.dylib 0x38a74797 pthread_kill + 58
2 libsystem_c.dylib 0x389bafdd abort + 76
3 libsystem_malloc.dylib 0x38a32d67 free + 382
4 libobjc.A.dylib 0x3844e3ad object_dispose + 20
5 UIKit 0x305511ef -[UIViewAnimationState dealloc] + 174
6 libobjc.A.dylib 0x38456b6b objc_object::sidetable_release(bool) + 174
7 CoreFoundation 0x2dc2d93d CFRelease + 556
8 QuartzCore 0x30195635 CA::release_objects(X::List<void const*>*) + 16
9 QuartzCore 0x3019aad7 -[CAAnimation dealloc] + 54
10 libobjc.A.dylib 0x38456b6b objc_object::sidetable_release(bool) + 174
11 CoreFoundation 0x2dc2d93d CFRelease + 556
12 QuartzCore 0x3019d117 CA::Layer::run_animation_callbacks(void*) + 238
13 libdispatch.dylib 0x3892f81f _dispatch_client_callout + 22
14 libdispatch.dylib 0x3893649f _dispatch_main_queue_callback_4CF$VARIANT$mp + 278
15 CoreFoundation 0x2dcc78f1 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
16 CoreFoundation 0x2dcc61c5 __CFRunLoopRun + 1300
17 CoreFoundation 0x2dc30f0f CFRunLoopRunSpecific + 522
18 CoreFoundation 0x2dc30cf3 CFRunLoopRunInMode + 106
19 GraphicsServices 0x32b52663 GSEventRunModal + 138
20 UIKit 0x3057c16d UIApplicationMain + 1136
21 Domino M 0x000c125f main (main.m:14)
Other threads only show the AFNetworking library doing something.
How can I find and fix issues like this (the ones that don't seem to have anything to do with self written code)?
I'm trying to analyze a log for what appears to be an intermittent crash.
Here's the stack trace for the thread that throws the exception:
Thread : Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x2ab5f49f __exceptionPreprocess + 126
1 libobjc.A.dylib 0x38315c8b objc_exception_throw + 38
2 CoreFoundation 0x2ab5f3e5 -[NSException initWithCoder:]
3 Foundation 0x2b862389 -[NSProxy doesNotRecognizeSelector:] + 68
4 CoreFoundation 0x2ab627d7 ___forwarding___ + 714
5 CoreFoundation 0x2aa94058 _CF_forwarding_prep_0 + 24
6 UIKit 0x292648cb -[UIScrollViewAccessibility _axCleanupDelegateClearer] + 98
7 UIKit 0x29264965 -[UIScrollViewAccessibility dealloc] + 60
8 UIKit 0x2e19c8b1 -[UITableView dealloc] + 1572
9 UIKit 0x2924dc91 -[UITableViewAccessibility dealloc] + 172
10 libobjc.A.dylib 0x38314da1 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
11 libobjc.A.dylib 0x3831e5f7 objc_destructInstance + 34
12 libobjc.A.dylib 0x3831e61b object_dispose + 14
13 UIKit 0x2e3214d1 -[UIResponder dealloc] + 96
14 UIKit 0x2e18eb55 -[UIViewController dealloc] + 1760
15 CoreFoundation 0x2aa6600d CFRelease + 600
16 CoreFoundation 0x2aa7968f -[__NSArrayI dealloc] + 66
17 libobjc.A.dylib 0x3832fd5f objc_object::sidetable_release(bool) + 166
18 libobjc.A.dylib 0x383301a9 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 404
19 CoreFoundation 0x2aa71149 _CFAutoreleasePoolPop + 16
20 UIKit 0x2e01789f _wrapRunLoopWithAutoreleasePoolHandler + 42
21 CoreFoundation 0x2ab25d95 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
22 CoreFoundation 0x2ab23453 __CFRunLoopDoObservers + 278
23 CoreFoundation 0x2ab2385b __CFRunLoopRun + 914
24 CoreFoundation 0x2aa713c1 CFRunLoopRunSpecific + 476
25 CoreFoundation 0x2aa711d3 CFRunLoopRunInMode + 106
26 GraphicsServices 0x31e6f0a9 GSEventRunModal + 136
27 UIKit 0x2e080fa1 UIApplicationMain + 1440
28 MyApp 0x000938b1 main (main.mm:21)
29 libdyld.dylib 0x38895aaf start + 2
And here's the stack trace for the main thread:
Thread : Crashed: com.apple.main-thread
0 libsystem_kernel.dylib 0x3895bdfc __pthread_kill + 8
1 libsystem_pthread.dylib 0x389d9d37 pthread_kill + 62
2 libsystem_c.dylib 0x388fb909 abort + 76
3 libc++abi.dylib 0x37c399c9 __cxa_bad_cast
4 libc++abi.dylib 0x37c53671 default_unexpected_handler()
5 libobjc.A.dylib 0x38315f25 _objc_terminate() + 192
6 libc++abi.dylib 0x37c50de3 std::__terminate(void (*)()) + 78
7 libc++abi.dylib 0x37c508af __cxa_rethrow + 102
8 libobjc.A.dylib 0x38315dd3 objc_exception_rethrow + 42
9 CoreFoundation 0x2aa7145d CFRunLoopRunSpecific + 632
10 CoreFoundation 0x2aa711d3 CFRunLoopRunInMode + 106
11 GraphicsServices 0x31e6f0a9 GSEventRunModal + 136
12 UIKit 0x2e080fa1 UIApplicationMain + 1440
13 MyApp 0x000938b1 main (main.mm:21)
Looking through the trace with the exception, I see a CF_forwarding_prep_0 message, which is followed by an [NSProxy doesNotRecognizeSelector] exception. Reading that, is it a safe assumption that the cause of the issue is that there's a pointer to a tableview delegate that isn't being set to nil? That's about the only discernible thing I see here.
Any help would be most appreciated. Thanks!