KVO observer crash on iOS 11 - ios

I’ve a app in App Store which was working fine on iOS 10. But recently I’m getting many crash reports and all logs points to KVO crash and all are happening on iOS 11, below is the crash log.
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x181e7a858 object_isClass + 16
1 Foundation 0x1836d72bc KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED + 68
2 Foundation 0x1836d5ad0 NSKeyValueWillChangeWithPerThreadPendingNotifications + 300
3 QuartzCore 0x186e35024 -[CALayer setDelegate:] + 108
4 UIKit 0x18c866698 -[UIView dealloc] + 708
5 UIKit 0x18c93f08c -[UILabel dealloc] + 192
6 libobjc.A.dylib 0x181e9a13c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 844
7 UIKit 0x18c86678c -[UIView dealloc] + 952
8 CoreFoundation 0x182b911b4 -[__NSArrayM dealloc] + 140
9 libobjc.A.dylib 0x181e9a13c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 844
10 UIKit 0x18c86678c -[UIView dealloc] + 952
11 libobjc.A.dylib 0x181e9a13c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 844
12 UIKit 0x18c86678c -[UIView dealloc] + 952
13 libobjc.A.dylib 0x181e9a13c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 844
14 UIKit 0x18c86678c -[UIView dealloc] + 952
15 UIKit 0x18cbd3248 -[UINavigationTransitionView dealloc] + 96
16 libobjc.A.dylib 0x181e9a13c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 844
17 UIKit 0x18c86678c -[UIView dealloc] + 952
18 UIKit 0x18cbd319c -[UILayoutContainerView dealloc] + 60
19 libobjc.A.dylib 0x181e9a13c (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 844
20 CoreFoundation 0x182b88aac _CFAutoreleasePoolPop + 28
21 UIKit 0x18cc705fc _prepareForCAFlush + 132
22 UIKit 0x18cb555b8 _afterCACommitHandler + 236
23 CoreFoundation 0x182c6a910 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
24 CoreFoundation 0x182c68238 __CFRunLoopDoObservers + 412
25 CoreFoundation 0x182c68884 __CFRunLoopRun + 1436
26 CoreFoundation 0x182b88da8 CFRunLoopRunSpecific + 552
27 GraphicsServices 0x184b6b020 GSEventRunModal + 100
28 UIKit 0x18cb6978c UIApplicationMain + 236
29 MyApp 0x1009bf748 main (main.m:14)
30 libdyld.dylib 0x182619fc0 start + 4
The crashes has crossed over 200 crashes and all are same logs. I’ve not been able to reproduce this crash and kind of stuck on how to proceed next. My entire project is written in objective-C and when I checked there is only one method where I’m using a KVO. Below is a model of my method on how I’ve used it.
-(void)loadData
{
//Some code
if (myAlerts) {
[myAlerts removeObserver:self forKeyPath:#“liveAlerts"];
}
myAlerts = myModel.alerts;
[myAlerts addObserver:self forKeyPath:#"liveAlerts" options:NSKeyValueObservingOptionInitial context:NULL];
}
To remove I use the cleanup method in other viewcontrollers when I no longer need it
-(void)cleanup
{
//Some code
[myAlerts removeObserver:self forKeyPath:#"liveAlerts"];
myAlerts = nil;
}
All the other observers which I've added in my project are NSNotificationCenter observers, could that cause this type of crash log?

Related

iOS: Bad access is cxx_descruct

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

weird SIGSEGV crash in iOS

About 10+ crash reported by crittercism.
Name: SIGSEGV
Reason: SEGV_MAPERR
Seems it is a UIScrollView/UITableView animating or scrolling issue.
How can I find the root cause?
Stack:
0
libobjc.A.dylib 0x0000000195fafbd0 objc_msgSend + 12
1
UIKit 0x00000001892b1db8 -[UIScrollView(UIScrollViewInternal) _delegateScrollViewAnimationEnded] + 64
2
UIKit 0x00000001892b1d30 -[UIScrollView(UIScrollViewInternal) _scrollViewAnimationEnded:finished:] + 204
3
UIKit 0x0000000189366814 -[UIAnimator stopAnimation:] + 500
4
UIKit 0x0000000189366248 -[UIAnimator(Static) _advanceAnimationsOfType:withTimestamp:] + 332
5
QuartzCore 0x0000000188b4629c CA::Display::DisplayLinkItem::dispatch() + 28
6
QuartzCore 0x0000000188b46134 CA::Display::DisplayLink::dispatch_items() + 320
7
IOKit 0x0000000185921470 IODispatchCalloutFromCFMessage + 372
8
CoreFoundation 0x0000000184712dc4 __CFMachPortPerform + 176
9
CoreFoundation 0x0000000184727a54 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
10
CoreFoundation 0x00000001847279b4 __CFRunLoopDoSource1 + 432
11
CoreFoundation 0x0000000184725934 __CFRunLoopRun + 1636
12
CoreFoundation 0x00000001846512d4 CFRunLoopRunSpecific + 392
13
GraphicsServices 0x000000018de676fc GSEventRunModal + 164
14
UIKit 0x0000000189216fac UIApplicationMain + 1484
15
MyApp 0x000000010001d280 main (main.m:14)
16
libdyld.dylib 0x000000019661aa08 start + 0
I've seen this happen when a controller and/or its table is deallocated during an animation. The OS still triggers delegate methods (e.g., -scrollViewDidEndScrollingAnimation: or -scrollViewDidEndDecelerating:) when it finishes with the animation, but because the objects no longer exist things get weird.
The best fix is to nil the delegate in the controller's dealloc method.

App Crashes when NavigationController is popped

App crashing when pop two times the navigationController and in iPhone log return this error :(
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x6545f661
Triggered by Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x3a081636 objc_msgSend + 22
1 UIKit 0x322bef20 -[UIScrollView(UIScrollViewInternal) _notifyDidScroll] + 60
2 UIKit 0x32039188 -[UIScrollView setContentOffset:] + 592
3 UIKit 0x320e61e6 -[UITableView setContentOffset:] + 346
4 UIKit 0x322bfe62 -[UIScrollView(UIScrollViewInternal) _adjustContentOffsetIfNecessary] + 1350
5 UIKit 0x320ebd0e -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 410
6 UIKit 0x320ebb66 -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:] + 26
7 UIKit 0x320ebb22 -[UIScrollView removeFromSuperview] + 26
8 UIKit 0x3201a3b6 -[UIView dealloc] + 374
9 libobjc.A.dylib 0x3a0870d2 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 354
10 CoreFoundation 0x2f730c14 _CFAutoreleasePoolPop + 12
11 CoreFoundation 0x2f7c6176 __CFRunLoopRun + 1302
12 CoreFoundation 0x2f730eba CFRunLoopRunSpecific + 518
13 CoreFoundation 0x2f730c9e CFRunLoopRunInMode + 102
14 GraphicsServices 0x3468a65e GSEventRunModal + 134
15 UIKit 0x3207d148 UIApplicationMain + 1132
16 Big24H 0x000e9728 main (main.m:16)
17 libdyld.dylib 0x3a584ab4 start + 0
Looks like you have a UIScrollViewDelegate being deallocated before its corresponding UIScrollView and then getting called.
You didn't provide any code so the best I can say is you need to find where it is and nil it out when it is getting deallocated.
Probably something like this:
- (void) dealloc
{
myScrollView.delegate = nil;
}

iOS Crash with name SIGSEGV, reason main

I'm using Crittercism (SDK 4.1.2) crash reporting service to catch reports on my iOS app. i've been getting this crash many times and i've no idea why it's happening.
Name: SIGSEGV - Reason: Main
Crashed Thread
0 libobjc.A.dylib 0x397c4b26 objc_msgSend + 6
1 UIKit 0x31965a2d -[UIScrollView(UIScrollViewInternal) _scrollViewAnimationEnded:finished:] + 177
2 UIKit 0x31a0e4b3 -[UIAnimator stopAnimation:] + 471
3 UIKit 0x31a0de9d -[UIAnimator(Static) _advanceAnimationsOfType:withTimestamp:] + 285
4 UIKit 0x31a0dd7d -[UIAnimator(Static) _LCDHeartbeatCallback:] + 53
5 QuartzCore 0x315419cf _ZN2CA7Display15DisplayLinkItem8dispatchEv + 99
6 QuartzCore 0x31541779 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 345
7 IOMobileFramebuffer 0x3411b76d IOMobileFramebufferVsyncNotifyFunc + 105
8 IOKit 0x2fdd9a75 IODispatchCalloutFromCFMessage + 249
9 CoreFoundation 0x2f0b7e21 __CFMachPortPerform + 137
10 CoreFoundation 0x2f0c29df __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 35
11 CoreFoundation 0x2f0c297b __CFRunLoopDoSource1 + 347
12 CoreFoundation 0x2f0c114f __CFRunLoopRun + 1399
13 CoreFoundation 0x2f02bc27 CFRunLoopRunSpecific + 523
14 CoreFoundation 0x2f02ba0b CFRunLoopRunInMode + 107
15 GraphicsServices 0x33cff283 GSEventRunModal + 139
16 UIKit 0x318cf049 UIApplicationMain + 1137
17 AppName 0x000b1fef main + 67
Not sure if this is the case for you, but I've had a similar crash caused by a button in an UIView trying to invoke a callback method on a already released object. The UI was displayed, and then the object was released.

Crash UIScrollView EXC_BAD_ACCESS

I'm having trouble to diagnostic a crash with UIScrollView
UIKit
-[UIScrollView setContentOffset:]
Exception Type: EXC_BAD_ACCESS Code KERN_INVALID_ADDRESS at 0xe0000008
com.apple.main-thread Crashed
0 libobjc.A.dylib objc_msgSend + 15
1 UIKit -[UIScrollView setContentOffset:] + 618
2 UIKit -[UITableView setContentOffset:] + 330
3 UIKit -[UIScrollView(Static) _adjustContentOffsetIfNecessary] + 1474
4 UIKit -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:tramplingDragFlags:] + 414
5 UIKit -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:pin:] + 30
6 UIKit -[UIScrollView removeFromSuperview] + 30
7 ... UIKit -[UIView dealloc] + 296
8 UIKit -[UIView dealloc] + 296
9 libobjc.A.dylib (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 168
10 CoreFoundation _CFAutoreleasePoolPop + 16
11 CoreFoundation __CFRunLoopRun + 1296
12 CoreFoundation CFRunLoopRunSpecific + 356
13 CoreFoundation CFRunLoopRunInMode + 104
14 GraphicsServices GSEventRunModal + 74
15 UIKit UIApplicationMain + 1120
16 iTV Shows main.m line 12
I had the same problem. Setting the TableView and ScrollView delegates (or any other delegates that you might have) to nil in the dealloc method solved the problem.
- (void)dealloc {
self.tableView.delegate = nil;
self.tableView.dataSource = nil;
}
Its hard to give a concrete answer without seeing your code, but the iOS Debugging Magic technical note is always a great resource with tips for debugging crashes.
Technical Note TN2239: iOS Debugging Magic

Resources