Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if UIScrollView crash is in my code or Apple's? [duplicate]

I periodically am reproing a crash on a debug build running on my iPhone involving a UIScrollView with none of my code in the stack frame. I would like to know if it's a bug in my code or Apple's, and I am unable to query the Apple bug database to see if it has been reported. The backtrace shows:

#0  0x30218060 in ___forwarding___ ()
#1  0x3020eda0 in __forwarding_prep_0___ ()
#2  0x309c4ce8 in -[UIScrollView(UIScrollViewInternal) _scrollViewAnimationEnded] ()
#3  0x3025af60 in -[NSObject performSelector:withObject:] ()
#4  0x3098ea94 in -[UIAnimator stopAnimation:] ()
#5  0x3098e5a8 in -[UIAnimator(Static) _advance:] ()
#6  0x3098e460 in LCDHeartbeatCallback ()
#7  0x32047fe8 in HeartbeatVBLCallback ()
#8  0x32a1c3ec in IOMobileFramebufferNotifyFunc ()
#9  0x3188a74c in IODispatchCalloutFromCFMessage ()
#10 0x3020d0b0 in __CFMachPortPerform ()
#11 0x30254a76 in CFRunLoopRunSpecific ()
#12 0x3025416a in CFRunLoopRunInMode ()
#13 0x320452a4 in GSEventRunModal ()
#14 0x308f037c in -[UIApplication _run] ()
#15 0x308eea94 in UIApplicationMain ()
#16 0x0000280c in main (argc=1, argv=0x2ffff58c) at /Users/esilver/Documents/Husband Material/main.m:14

The problem is apparently in UIScrollView(UIScrollViewInternal) _scrollViewAnimationEnded. GDB reports:

-[MyViewController respondsToSelector:]: message sent to deallocated instance 0x5d77ad0

In MyViewController, I do have a call to scroll a tableView:

[self.tableView scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];  

Because it's animated, it's clearly possible that the view could get popped off the navigation controller before the scrolling animation completes. It seems like it should be the job of the UIView to cancel or wait for any pending scrolling operations when it is unloading. Therefore, I think this is a bug in Apple's code.

Or am I mistaken, and is there some kind of checking my view must do check if it's scrolling prior to unloading, or am I misreading this crash entirely?

FYI, this bug also only appears to repro in low-memory conditions, i.e. I have started receiving didReceiveMemoryWarning callbacks.

Thanks all,

Eric

like image 807
esilver Avatar asked Nov 15 '22 12:11

esilver


1 Answers

At first, delegates should be of weak/assign type. But event in this case there is a very common subtle obstacle driven by scroll animations. If you use animated content offset changes for your ScrollViews you strongly need to set its delegate to nil at dealloc method.

Otherwise you will get the following

[YourViewController respondsToSelector:]: message sent to deallocated instance

The very common example:

1. _tableView is ivar of YourViewController
2. _tableView.delegate = self;
3. - (void)scrollViewDidScroll:(UIScrollView *)scrollView is implemented at YourViewController
4. at some point you call [_tableView scrollToRowAtIndexPath:indexPath 
   atScrollPosition:UITableViewScrollPositionBottom animated:YES];
   or [_tableView setContentOffset:CGPoint animated:YES]
   and try to close YourViewController

The _tableView is retained by CoreAnimation, but YourViewController is deallocated!

like image 126
malex Avatar answered Dec 14 '22 23:12

malex