Getting weird crash on changing device orientation twice - ios

I am navigationcontroller view ,with toolbar,search bar & tableview.
On device orienatation change twice i see weird
*** -[UIImage isKindOfClass:]: message sent to deallocated instance 0x7a31c00
(lldb) bt
* thread #1: tid = 0x1f03, 0x93e06332 libsystem_kernel.dylib`__kill + 10, stop reason = signal SIGKILL
frame #0: 0x93e06332 libsystem_kernel.dylib`__kill + 10
frame #1: 0x93e05932 libsystem_kernel.dylib`kill$UNIX2003 + 32
frame #2: 0x01e10e03 CoreFoundation`___forwarding___ + 227
frame #3: 0x01e10cb2 CoreFoundation`_CF_forwarding_prep_0 + 50
frame #4: 0x00ae1a06 UIKit`-[UIImageView _setViewGeometry:forMetric:] + 295
frame #5: 0x00ae1c2d UIKit`-[UIImageView setFrame:] + 63
frame #6: 0x00a2b9f2 UIKit`-[UIView(Geometry) _resizeWithOldSuperviewSize:] + 838
frame #7: 0x00a2c08a UIKit`-[UIView(Geometry) resizeWithOldSuperviewSize:] + 72
frame #8: 0x00a2b3b5 UIKit`__46-[UIView(Geometry) resizeSubviewsWithOldSize:]_block_invoke_0 + 73
frame #9: 0x01e41f1a CoreFoundation`__NSArrayChunkIterate + 362
frame #10: 0x01e0d635 CoreFoundation`__NSArrayEnumerate + 997
frame #11: 0x01e0d026 CoreFoundation`-[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
frame #12: 0x00a2b353 UIKit`-[UIView(Geometry) resizeSubviewsWithOldSize:] + 149
frame #13: 0x00a2a058 UIKit`-[UIView(Geometry) setFrame:] + 358
frame #14: 0x00abaf20 UIKit`-[UIViewControllerWrapperView setFrame:] + 193
frame #15: 0x00acfc13 UIKit`-[UINavigationController _layoutViewController:] + 335
frame #16: 0x00acf81c UIKit`-[UINavigationController _layoutTopViewController] + 155
frame #17: 0x00ad0899 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded] + 346
frame #18: 0x00ad09e1 UIKit`-[UINavigationController __viewWillLayoutSubviews] + 33
frame #19: 0x00bee5c2 UIKit`-[UILayoutContainerView layoutSubviews] + 222
frame #20: 0x00a34d21 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 145
frame #21: 0x01eabe42 CoreFoundation`-[NSObject performSelector:withObject:] + 66
frame #22: 0x0304e679 QuartzCore`-[CALayer layoutSublayers] + 266
frame #23: 0x03058579 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 231
frame #24: 0x0304e740 QuartzCore`-[CALayer layoutIfNeeded] + 184
frame #25: 0x00a2e938 UIKit`-[UIView(Hierarchy) layoutIfNeeded] + 42
frame #26: 0x00ac898a UIKit`-[UIViewController window:willAnimateRotationToInterfaceOrientation:duration:] + 565
frame #27: 0x00a21ef9 UIKit`-[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 4712
frame #28: 0x00a20c8c UIKit`-[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 82
frame #29: 0x00a20b97 UIKit`-[UIWindow _setRotatableViewOrientation:duration:force:] + 93
frame #30: 0x00a2017b UIKit`-[UIWindow _updateToInterfaceOrientation:duration:force:] + 228
frame #31: 0x00a202ac UIKit`-[UIWindow _updateInterfaceOrientationFromDeviceOrientation:] + 162
frame #32: 0x00a20203 UIKit`-[UIWindow _updateInterfaceOrientationFromDeviceOrientationIfRotationEnabled:] + 82
frame #33: 0x00a20028 UIKit`-[UIWindow _handleDeviceOrientationChange:] + 121
frame #34: 0x013b8a29 Foundation`__57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 40
frame #35: 0x01e75855 CoreFoundation`___CFXNotificationPost_block_invoke_0 + 85
frame #36: 0x01e75778 CoreFoundation`_CFXNotificationPost + 1976
frame #37: 0x012fd19a Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 98
frame #38: 0x00bccdb1 UIKit`-[UIDevice setOrientation:animated:] + 220
frame #39: 0x00a042fd UIKit`-[UIApplication handleEvent:withNewEvent:] + 1405
frame #40: 0x00a04c38 UIKit`-[UIApplication sendEvent:] + 68
frame #41: 0x009f8634 UIKit`_UIApplicationHandleEvent + 8196
frame #42: 0x01cadef5 GraphicsServices`PurpleEventCallback + 1274
frame #43: 0x01e7e195 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
frame #44: 0x01de2ff2 CoreFoundation`__CFRunLoopDoSource1 + 146
frame #45: 0x01de18da CoreFoundation`__CFRunLoopRun + 2218
frame #46: 0x01de0d84 CoreFoundation`CFRunLoopRunSpecific + 212
frame #47: 0x01de0c9b CoreFoundation`CFRunLoopRunInMode + 123
frame #48: 0x01cac7d8 GraphicsServices`GSEventRunModal + 190
frame #49: 0x01cac88a GraphicsServices`GSEventRun + 103
frame #50: 0x009f6626 UIKit`UIApplicationMain + 1163
I dont have any code inside delegate
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
shouldAutorotateToInterfaceOrientation supports all orientation
I could find cause of crash

I overide UItoolbar class to create custom toolbar with image in background.which cause crash on orientation change
#interface CustomWhiteToolbar : UIToolbar {
}
#end
#implementation CustomWhiteToolbar
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
UIImage *img = [UIImage imageNamed: #"White_bordered_background.png"];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
[img release];
self.tintColor = [UIColor clearColor];
}
#end
this cause crash on orientation changes.I have custom toolbar class set to toolbar inside my xib.I couldnt find why did that crash

Related

UINavigationController method setToolbarHidden bug in Xcode 9: infinite calculation of auto-layout constraints leads to OOM

I have an instance of UINavigationController nested in UITabBarController. I use the navigation controller to reach some view controller (tab bar still visible), from which I segue to a second view controller (tab bar no longer visible).
In the second view controller, as soon as I make a call to:
[self.navigationController setToolbarHidden:NO]
the app freezes and memory grows until OOM exception crashes it.
I acknowledge that nesting the navigation controller inside the tab bar is not recommended, but this setup seemed to work fine until iOS 11.
EDIT: when stopping execution, I see a lot of calls to:
UIView(UIConstraintBasedLayout)
UIView(AdditionalLayerSupport)
NSLayoutConstraint
Here's the full stack trace
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP * frame #0: 0x0000000106dd895c libobjc.A.dylib`objc_msgSend
+ 28
frame #1: 0x00000001067b6b9b Foundation`-[NSConcreteMapTable removeObjectForKey:] + 138
frame #2: 0x00000001069e6019 Foundation`_substituteOutAllOccurencesOfBodyVar + 1282
frame #3: 0x00000001067f3c5b Foundation`-[NSISEngine tryAddingDirectly:] + 144
frame #4: 0x00000001067f332f Foundation`-[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:]
+ 440
frame #5: 0x00000001069f2067 Foundation`-[NSLayoutConstraint _addLoweredExpression:toEngine:integralizationAdjustment:lastLoweredConstantWasRounded:mutuallyExclusiveConstraints:]
+ 273
frame #6: 0x00000001067ea601 Foundation`-[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 240
frame #7: 0x0000000109c9488d UIKit`__57-[UIView(AdditionalLayoutSupport)
_switchToLayoutEngine:]_block_invoke_2 + 452
frame #8: 0x00000001067f0de1 Foundation`-[NSISEngine withBehaviors:performModifications:] + 131
frame #9: 0x0000000109c946a2 UIKit`__57-[UIView(AdditionalLayoutSupport)
_switchToLayoutEngine:]_block_invoke + 604
frame #10: 0x0000000109c9441e UIKit`-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 223
frame #11: 0x00000001091ed84f UIKit`__45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 112
frame #12: 0x00000001067f0de1 Foundation`-[NSISEngine withBehaviors:performModifications:] + 131
frame #13: 0x00000001091ed778 UIKit`-[UIView(Hierarchy) _postMovedFromSuperview:] + 855
frame #14: 0x00000001091fe031 UIKit`-[UIView(Internal) _addSubview:positioned:relativeTo:] + 1927
frame #15: 0x0000000109b507e1 UIKit`-[_UILayoutArrangement insertItem:atIndex:] + 502
frame #16: 0x0000000109ca1b4d UIKit`__50-[_UIOrderedLayoutArrangement insertItem:atIndex:]_block_invoke + 50
frame #17: 0x0000000109ca18df UIKit`-[_UIOrderedLayoutArrangement _trackChangesAffectingExternalBaselineConstraints:] + 320
frame #18: 0x0000000109ca1aea UIKit`-[_UIOrderedLayoutArrangement insertItem:atIndex:] + 478
frame #19: 0x000000010982edea UIKit`-[UIStackView insertArrangedSubview:atIndex:] + 283
frame #20: 0x0000000109b29972 UIKit`-[_UIButtonBar _layoutBar] + 3639
frame #21: 0x0000000109b2bb44 UIKit`-[_UIButtonBarStackView updateConstraints] + 48
frame #22: 0x0000000109c958b6 UIKit`-[UIView(AdditionalLayoutSupport)
_sendUpdateConstraintsIfNecessaryForSecondPass:] + 161
frame #23: 0x0000000109c95ed2 UIKit`-[UIView(AdditionalLayoutSupport)
_updateConstraintsIfNeededCollectingViews:forSecondPass:] + 1296
frame #24: 0x0000000109c95d51 UIKit`-[UIView(AdditionalLayoutSupport)
_updateConstraintsIfNeededCollectingViews:forSecondPass:] + 911
frame #25: 0x0000000109c95d51 UIKit`-[UIView(AdditionalLayoutSupport)
_updateConstraintsIfNeededCollectingViews:forSecondPass:] + 911
frame #26: 0x0000000109c95d51 UIKit`-[UIView(AdditionalLayoutSupport)
_updateConstraintsIfNeededCollectingViews:forSecondPass:] + 911
frame #27: 0x00000001067f0de1 Foundation`-[NSISEngine withBehaviors:performModifications:] + 131
frame #28: 0x0000000109c96703 UIKit`__100-[UIView(AdditionalLayoutSupport)
_updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke
+ 90
frame #29: 0x0000000109c94f61 UIKit`-[UIView(AdditionalLayoutSupport)
_withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 104
frame #30: 0x0000000109c96272 UIKit`-[UIView(AdditionalLayoutSupport)
_updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 160
frame #31: 0x0000000109c9738c UIKit`-[UIView(AdditionalLayoutSupport)
_updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:]
+ 401
frame #32: 0x00000001091ef1b6 UIKit`-[UIView(Hierarchy) layoutBelowIfNeeded] + 1517
frame #33: 0x000000010957b35e UIKit`-[_UIButtonBarButton willMoveToWindow:] + 63
frame #34: 0x00000001091ec996 UIKit`-[UIView(Hierarchy) _willMoveToWindow:] + 861
frame #35: 0x00000001091eb493 UIKit`__UIViewWillBeRemovedFromSuperview + 484
frame #36: 0x00000001091eb0ea UIKit`-[UIView(Hierarchy) removeFromSuperview] + 95
frame #37: 0x0000000109b295d3 UIKit`-[_UIButtonBar _layoutBar] + 2712
frame #38: 0x0000000109b2bb44 UIKit`-[_UIButtonBarStackView updateConstraints] + 48
frame #39: 0x0000000109c958b6 UIKit`-[UIView(AdditionalLayoutSupport)
_sendUpdateConstraintsIfNecessaryForSecondPass:] + 161
frame #40: 0x0000000109c95ed2 UIKit`-[UIView(AdditionalLayoutSupport)
_updateConstraintsIfNeededCollectingViews:forSecondPass:] + 1296
frame #41: 0x0000000109c95d51 UIKit`-[UIView(AdditionalLayoutSupport)
_updateConstraintsIfNeededCollectingViews:forSecondPass:] + 911
frame #42: 0x0000000109c95d51 UIKit`-[UIView(AdditionalLayoutSupport)
_updateConstraintsIfNeededCollectingViews:forSecondPass:] + 911
frame #43: 0x0000000109c95d51 UIKit`-[UIView(AdditionalLayoutSupport)
_updateConstraintsIfNeededCollectingViews:forSecondPass:] + 911
frame #44: 0x00000001067f0de1 Foundation`-[NSISEngine withBehaviors:performModifications:] + 131
frame #45: 0x0000000109c96703 UIKit`__100-[UIView(AdditionalLayoutSupport)
_updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke
+ 90
frame #46: 0x0000000109c94f61 UIKit`-[UIView(AdditionalLayoutSupport)
_withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 104
frame #47: 0x0000000109c96272 UIKit`-[UIView(AdditionalLayoutSupport)
_updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 160
frame #48: 0x0000000109c9738c UIKit`-[UIView(AdditionalLayoutSupport)
_updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:]
+ 401
frame #49: 0x00000001091efa5b UIKit`-[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 159
frame #50: 0x00000001095742d5 UIKit`-[UILayoutContainerView layoutSubviews] + 270
frame #51: 0x0000000109204551 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1331
frame #52: 0x00000001064db4ba QuartzCore`-[CALayer layoutSublayers] + 153
frame #53: 0x00000001064df5a9 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 401
frame #54: 0x00000001064681cd QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 365
frame #55: 0x0000000106493ae4 QuartzCore`CA::Transaction::commit() + 500
frame #56: 0x0000000109160687 UIKit`_afterCACommitHandler + 272
frame #57: 0x00000001080f8db7 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
+ 23
frame #58: 0x00000001080f8d0e CoreFoundation`__CFRunLoopDoObservers + 430
frame #59: 0x00000001080dd324 CoreFoundation`__CFRunLoopRun + 1572
frame #60: 0x00000001080dca89 CoreFoundation`CFRunLoopRunSpecific + 409
frame #61: 0x000000010dc429c6 GraphicsServices`GSEventRunModal + 62
frame #62: 0x0000000109135d30 UIKit`UIApplicationMain + 159
frame #63: 0x0000000101ff6bf9 MyAppName`main(argc=1, argv=0x00007fff5de3e0a8) at main.m:23
frame #64: 0x000000010f453d81 libdyld.dylib`start + 1
frame #65: 0x000000010f453d81 libdyld.dylib`start + 1
This is the answer from a developer from the same team as OP is from.
After one more round of research we have found that the problem was on our side:
- (NSArray *)toolbarItems
{
return [self toolbarItemsWithRunningAdditionalAnimation:NO];
}
Original developer made the method toolbarItemsWithRunningAdditionalAnimation to return new objects each time the method was called. When going to this controller iOS calls toolbarItems at least 3 times so giving it new objects every time we made iOS confused so it was recalculating auto-layout constraints in an infinite loop. Our original fix below is also working, however it becomes obsolete as we start always returning the same array of items like:
- (NSArray *)toolbarItems {
if (_cachedToolbarItems) { return _cachedToolbarItems; }
_cachedToolbarItems = [self toolbarItemsWithRunningAdditionalAnimation:NO];
return _cachedToolbarItems'
}
We are doing the following in our app (pseudocode):
UIToolbar *toolbar = self.navigationController.toolbar;
NSArray <UIBarButtonItem *> *items = #[
flexibleSpace,
share,
flexibleSpace,
play,
flexibleSpace,
stats,
flexibleSpace
];
[toolbar setItems:items animated:animated];
[self.navigationController setToolbarHidden:NO animated:animated];
The problematic items that caused infinite calculation of auto-layout constraints were share and stats. The thing they both had in common - they both were created using -[UIBarButtonItem initWithImage:style:target:action:] initializer. When we started using another initializer:
UIButton *customShareButton = ... // we create button ourselves.
UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithCustomView: customShareButton];
The problem went away.
Besides the accepted answer, we found that our problem was related to the fact that in our class, we override the method
- (NSArray *)toolbarItems.
Every time our method is called, a new set of toolbarItems is created.
Seems like from iOS 11, every time new toolbar items are returned to this method, UINavigationController:layoutIfNeeded is called again, which in turn calls toolbarItems which returns new items because of our implementation. This causes an infinite loop.
If you encounter this problem, check if you are overriding - (NSArray *)toolbarItems

UIWebView Crashing on Drop Down

We are loading HTML with Select control (Drop Down) in UIWebView and when we click on Drop down, the app is crashing. This is happening only when text having lengthy text, but works fine with short Text.
When we debugged, we found its an issue with UILabel in UIPopoverController coming from UIWebView. When UILabel has text with 2 lines, this issue is happening, single line its fine. We are unable to identify the issue whether its with Storyboard or Settings...etc.
Any help will be much appreciated.
Here is the Crash
* thread #1: tid = 0x1bd3, 0x034ad930 CoreFoundation`CFArrayGetValueAtIndex + 112, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x034ad930 CoreFoundation`CFArrayGetValueAtIndex + 112
frame #1: 0x007d1b41 CoreText`TCharStream::CopyBreakIterator(__CFString const*) + 261
frame #2: 0x007d18f4 CoreText`TCharStream::FindLineBreak(CFRange, bool, __CFString const*) const + 246
frame #3: 0x00758a4a CoreText`TTypesetter::SuggestLineBreak(TLine const&, long, double, double) + 328
frame #4: 0x007586b9 CoreText`CTLineSuggestLineBreakWithOffset + 55
frame #5: 0x0839d89f UIFoundation`__NSStringDrawingEngine + 20275
frame #6: 0x08398940 UIFoundation`-[NSString(NSExtendedStringDrawing) boundingRectWithSize:options:attributes:context:] + 201
frame #7: 0x01b265c1 UIKit`-[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 1425
frame #8: 0x01b25e7e UIKit`-[UILabel textRectForBounds:limitedToNumberOfLines:] + 85
frame #9: 0x01d1d0cb UIKit`-[UITableViewCellLayoutManager intrinsicContentSizeForCell:] + 554
frame #10: 0x01c16594 UIKit`-[UITableViewCell sizeThatFits:] + 46
frame #11: 0x02092ade UIKit`-[UIView(UIConstraintBasedLayout) systemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority:] + 130
frame #12: 0x01c01c9f UIKit`-[UITableViewCell systemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority:] + 220
frame #13: 0x01a3f847 UIKit`-[UITableView _heightForCell:atIndexPath:] + 386
frame #14: 0x01a302fb UIKit`__53-[UITableView _configureCellForDisplay:forIndexPath:]_block_invoke + 2244
frame #15: 0x019987af UIKit`+[UIView(Animation) performWithoutAnimation:] + 82
frame #16: 0x019987f8 UIKit`+[UIView(Animation) _performWithoutAnimation:] + 40
frame #17: 0x01a2fa2f UIKit`-[UITableView _configureCellForDisplay:forIndexPath:] + 355
frame #18: 0x01a381da UIKit`-[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 503
frame #19: 0x01a3829e UIKit`-[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 77
frame #20: 0x01a11a6b UIKit`-[UITableView _updateVisibleCellsNow:isRecursive:] + 3034
frame #21: 0x01a2c3d1 UIKit`-[UITableView layoutSubviews] + 222
frame #22: 0x019a1dd1 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 608
frame #23: 0x02f55771 libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
frame #24: 0x0061f28f QuartzCore`-[CALayer layoutSublayers] + 152
frame #25: 0x00613115 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 397
frame #26: 0x00612f70 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 26
frame #27: 0x005713c6 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 284
frame #28: 0x0057278c QuartzCore`CA::Transaction::commit() + 392
frame #29: 0x00572e58 QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
frame #30: 0x034fa9de CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
frame #31: 0x034fa920 CoreFoundation`__CFRunLoopDoObservers + 400
frame #32: 0x034f035a CoreFoundation`__CFRunLoopRun + 1226
frame #33: 0x034efbcb CoreFoundation`CFRunLoopRunSpecific + 443
frame #34: 0x034ef9fb CoreFoundation`CFRunLoopRunInMode + 123
frame #35: 0x04d4224f GraphicsServices`GSEventRunModal + 192
frame #36: 0x04d4208c GraphicsServices`GSEventRun + 104
frame #37: 0x019168b6 UIKit`UIApplicationMain + 1526
* frame #38: 0x000f85bd main(argc=1, argv=0xbff5e584) + 141 at main.m:16
frame #39: 0x04400ac9 libdyld.dylibstart + 1
Thanks,
Vijay
This is a duplicate, see my answer here: https://stackoverflow.com/a/26692948/4206060
In short, put this into your web view delegate:
-(void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_USEC), dispatch_get_main_queue(),
^{
[super presentViewController:viewControllerToPresent animated:flag completion:completion];
});
}
This is solved. The issue was because of hardcoding "AppleLanguages" NSDefaults Key to a String. When UIWebview tries to show UILabel it tries to fetch AppleLanguages as Array and crashing.

Animation with CGAffineTransformScale freezes application

I am trying to implement a "disappearing" url bar, when the users scrolls in the webview.
The function below gets called in - (void)scrollViewDidScroll:(UIScrollView *)scrollView.
For specific webpages the app freezes completely and uses 100% CPU. From trial and error we concluded that removing the CGAffineTransformScale fixes this. I am trying to understand why this happens and how else I could implement the same functionality.
- (void)collapseQueryBox
{
_URLBarState = CLQURLBarStateCollapsing;
_queryBoxViewHeightConstraint.constant = COLLAPSED_QUERYBOX_HEIGHT;
[UIView animateWithDuration:COLLAPSE_ANIMATION_DURATION animations:^{
_webView.scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
_queryLabel.transform = CGAffineTransformScale(_queryLabel.transform, COLLAPSE_ANIMATION_SCALE_FACTOR, COLLAPSE_ANIMATION_SCALE_FACTOR);
_queryLabel.layer.backgroundColor = [UIColor clearColor].CGColor;
[_browserContainerView layoutIfNeeded];
} completion:^(BOOL finished) {
_URLBarState = CLQURLBarStateCollapsed;
}];
}
The full stack trace of the paused app in the frozen state:
* thread #1: tid = 0xcbf9f, 0x025b40be libobjc.A.dylib`objc_msgSend + 26, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
* frame #0: 0x025b40be libobjc.A.dylib`objc_msgSend + 26
frame #1: 0x008cf411 Foundation`-[NSISEngine variableToWorkOnAmongVariablesWithIntegralizationViolationsIgnoringLostCauses:varsAlreadyAdjusted:] + 491
frame #2: 0x00a41ea3 Foundation`__44-[NSISEngine fixupIntegralizationViolations]_block_invoke + 1285
frame #3: 0x00a4368c Foundation`-[NSISEngine withBehaviors:performModifications:] + 107
frame #4: 0x008cf21a Foundation`-[NSISEngine withoutOptimizingAtEndRunBlockWithAutomaticOptimizationDisabled:] + 48
frame #5: 0x008cf1d9 Foundation`-[NSISEngine fixupIntegralizationViolations] + 96
frame #6: 0x008ceef8 Foundation`-[NSISEngine optimize] + 204
frame #7: 0x008d57e3 Foundation`-[NSISEngine constraintDidChangeSuchThatMarker:shouldBeReplacedByMarkerPlusDelta:] + 336
frame #8: 0x00a43e23 Foundation`-[NSISEngine tryToChangeConstraintSuchThatMarker:isReplacedByMarkerPlusDelta:undoHandler:] + 489
frame #9: 0x00a4b2d5 Foundation`-[NSLayoutConstraint _tryToChangeContainerGeometryWithUndoHandler:] + 578
frame #10: 0x008c8d4f Foundation`-[NSLayoutConstraint _setSymbolicConstant:constant:] + 384
frame #11: 0x008cb6a1 Foundation`-[NSLayoutConstraint setConstant:] + 52
frame #12: 0x00e398a5 UIKit`-[UIScrollView setContentSize:] + 566
frame #13: 0x01030a5a UIKit`-[UITableViewCell _updateWrapperContentInset] + 117
frame #14: 0x0103963a UIKit`-[UITableViewCell setFrame:] + 701
frame #15: 0x00e1b7b0 UIKit`-[UIView(Geometry) _applyAutoresizingMaskWithOldSuperviewSize:] + 840
frame #16: 0x00e1c552 UIKit`-[UIView(Geometry) _resizeWithOldSuperviewSize:] + 290
frame #17: 0x00e1c5aa UIKit`-[UIView(Geometry) resizeWithOldSuperviewSize:] + 80
frame #18: 0x00e1b185 UIKit`__46-[UIView(Geometry) resizeSubviewsWithOldSize:]_block_invoke + 87
frame #19: 0x028a1d86 CoreFoundation`__53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 102
frame #20: 0x028a1c5f CoreFoundation`-[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 239
frame #21: 0x00e1b115 UIKit`-[UIView(Geometry) resizeSubviewsWithOldSize:] + 149
frame #22: 0x00e19c4e UIKit`-[UIView(Geometry) setFrame:] + 559
frame #23: 0x00e1b7b0 UIKit`-[UIView(Geometry) _applyAutoresizingMaskWithOldSuperviewSize:] + 840
frame #24: 0x00e1c552 UIKit`-[UIView(Geometry) _resizeWithOldSuperviewSize:] + 290
frame #25: 0x00e1c5aa UIKit`-[UIView(Geometry) resizeWithOldSuperviewSize:] + 80
frame #26: 0x00e1b185 UIKit`__46-[UIView(Geometry) resizeSubviewsWithOldSize:]_block_invoke + 87
frame #27: 0x028a1d86 CoreFoundation`__53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 102
frame #28: 0x028a1c5f CoreFoundation`-[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 239
frame #29: 0x00e1b115 UIKit`-[UIView(Geometry) resizeSubviewsWithOldSize:] + 149
frame #30: 0x00eadc1a UIKit`-[UITableView resizeSubviewsWithOldSize:] + 98
frame #31: 0x00e1c819 UIKit`-[UIView(Geometry) setBounds:] + 510
frame #32: 0x00e39627 UIKit`-[UIScrollView setBounds:] + 1036
frame #33: 0x00eadf5f UIKit`-[UITableView setBounds:] + 260
frame #34: 0x00e1befd UIKit`-[UIView(Geometry) _applyISEngineLayoutValues] + 324
frame #35: 0x00e1c4c0 UIKit`-[UIView(Geometry) _resizeWithOldSuperviewSize:] + 144
frame #36: 0x00e457bb UIKit`-[UIScrollView _resizeWithOldSuperviewSize:] + 73
frame #37: 0x00e1c5aa UIKit`-[UIView(Geometry) resizeWithOldSuperviewSize:] + 80
frame #38: 0x00e1b185 UIKit`__46-[UIView(Geometry) resizeSubviewsWithOldSize:]_block_invoke + 87
frame #39: 0x028a1d86 CoreFoundation`__53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 102
frame #40: 0x028a1c5f CoreFoundation`-[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 239
frame #41: 0x00e1b115 UIKit`-[UIView(Geometry) resizeSubviewsWithOldSize:] + 149
frame #42: 0x0145961c UIKit`-[UIView(AdditionalLayoutSupport) _is_layout] + 158
frame #43: 0x00e20336 UIKit`-[UIView(Hierarchy) layoutSubviews] + 80
frame #44: 0x00e2d964 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
frame #45: 0x025b682b libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
frame #46: 0x01df345a QuartzCore`-[CALayer layoutSublayers] + 148
frame #47: 0x01de7244 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 380
frame #48: 0x01de70b0 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 26
frame #49: 0x01d4d7fa QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 294
frame #50: 0x01d4eb85 QuartzCore`CA::Transaction::commit() + 393
frame #51: 0x01d4f258 QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 92
frame #52: 0x027ed36e CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
frame #53: 0x027ed2bf CoreFoundation`__CFRunLoopDoObservers + 399
frame #54: 0x027cb254 CoreFoundation`__CFRunLoopRun + 1076
frame #55: 0x027ca9d3 CoreFoundation`CFRunLoopRunSpecific + 467
frame #56: 0x027ca7eb CoreFoundation`CFRunLoopRunInMode + 123
frame #57: 0x041895ee GraphicsServices`GSEventRunModal + 192
frame #58: 0x0418942b GraphicsServices`GSEventRun + 104
frame #59: 0x00dbef9b UIKit`UIApplicationMain + 1225

understanding 'lldb' backtace - app crashes when button is pressed

When I click on any button my app crashes. It throws a lldb run time error. I printed the backtrace:
* thread #1: tid = 0x2aaf3, 0x000000018db701c0 libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 2.1
frame #0: 0x000000018db701c0 libobjc.A.dylib`objc_exception_throw
frame #1: 0x0000000181666bd4 CoreFoundation`-[NSException raise] + 12
frame #2: 0x0000000182124720 Foundation`-[NSObject(NSKeyValueCoding) setValue:forKey:] + 256
frame #3: 0x00000001815b25ec CoreFoundation`-[NSArray makeObjectsPerformSelector:] + 248
frame #4: 0x00000001849eadd0 UIKit`-[UINib instantiateWithOwner:options:] + 1232
frame #5: 0x000000018492f878 UIKit`-[UIViewController _loadViewFromNibNamed:bundle:] + 280
frame #6: 0x0000000184630488 UIKit`-[UIViewController loadViewIfRequired] + 88
frame #7: 0x00000001846303f4 UIKit`-[UIViewController view] + 32
frame #8: 0x00000001847dd868 UIKit`-[UINavigationController _startCustomTransition:] + 704
frame #9: 0x00000001846e7f54 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 464
frame #10: 0x00000001846e7d24 UIKit`-[UINavigationController __viewWillLayoutSubviews] + 56
frame #11: 0x00000001846e7ca4 UIKit`-[UILayoutContainerView layoutSubviews] + 200
frame #12: 0x000000018462aff8 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 348
frame #13: 0x000000018421c258 QuartzCore`-[CALayer layoutSublayers] + 184
frame #14: 0x0000000184216e20 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 300
frame #15: 0x0000000184216cd8 QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
frame #16: 0x0000000184216560 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 280
frame #17: 0x0000000184216304 QuartzCore`CA::Transaction::commit() + 424
frame #18: 0x000000018420fc38 QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 80
frame #19: 0x00000001816276a8 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
frame #20: 0x0000000181624930 CoreFoundation`__CFRunLoopDoObservers + 372
frame #21: 0x0000000181624cbc CoreFoundation`__CFRunLoopRun + 764
frame #22: 0x0000000181565c20 CoreFoundation`CFRunLoopRunSpecific + 452
frame #23: 0x000000018724dc0c GraphicsServices`GSEventRunModal + 168
frame #24: 0x0000000184696fdc UIKit`UIApplicationMain + 1156
* frame #25: 0x00000001001297a4 myapp`main(argc=1, argv=0x000000016fd33ca8) + 116 at main.m:16
frame #26: 0x000000018e163aa0 libdyld.dylib`start + 4
What does it mean?
This is your problem:
Foundation`-[NSObject(NSKeyValueCoding) setValue:forKey:]
because after this, is raised an Exception:
CoreFoundation`-[NSException raise] + 12
You are trying to set a value for a key in your object that could not exists or has some other problem.
P.S.: Update your answer with some relevant code so I can update my answer with more explanations.

weird EXC_BAD_ACCESS in [UICollectionViewLayout dealloc]

I push a view controller that contains a UICollectionView onto a navigation controller. When I pop it to return to the previous VC, I get an EXC_BAD_ACCESS code=2. I have NSZombies enabled and it stops at the end (the line with the "}") of the dealloc method of my UICollectionViewLayout subclass. This is the stack trace:
* thread #1: tid = 0x70505, 0x030620b0 libobjc.A.dylib`objc_msgSend + 12, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=2, address=0x2)
frame #0: 0x030620b0 libobjc.A.dylib`objc_msgSend + 12
frame #1: 0x00f6812e UIKit`-[UICollectionViewLayout dealloc] + 226
frame #2: 0x000526ce MyDog`-[UICollectionViewWaterfallLayout dealloc](self=0x1da8e010, _cmd=0x03068678) + 206 at UICollectionViewWaterfallLayout.m:69
frame #3: 0x03063692 libobjc.A.dylib`objc_object::sidetable_release(bool) + 268
frame #4: 0x03064adf libobjc.A.dylib`-[NSObject release] + 25
frame #5: 0x00f87f50 UIKit`-[UICollectionViewData dealloc] + 45
frame #6: 0x03063692 libobjc.A.dylib`objc_object::sidetable_release(bool) + 268
frame #7: 0x03064adf libobjc.A.dylib`-[NSObject release] + 25
frame #8: 0x00f4a773 UIKit`-[UICollectionView dealloc] + 260
frame #9: 0x0098dd34 UIKit`-[UIView release] + 89
frame #10: 0x03062e97 libobjc.A.dylib`objc_release + 71
frame #11: 0x03062e3e libobjc.A.dylib`objc_storeStrong + 39
frame #12: 0x00040160 MyDog`-[MDProfileViewController dealloc](self=0x0dd1dd00, _cmd=0x03068678) + 96 at MDProfileViewController.m:83
frame #13: 0x00a4d275 UIKit`-[UIViewController release] + 89
frame #14: 0x03062e97 libobjc.A.dylib`objc_release + 71
frame #15: 0x009347bc UIKit`__destroy_helper_block_121 + 124
frame #16: 0x06d5e7a5 libsystem_sim_blocks.dylib`_Block_release + 207
frame #17: 0x009a1a4f UIKit`-[UIViewAnimationBlockDelegate dealloc] + 66
frame #18: 0x03063692 libobjc.A.dylib`objc_object::sidetable_release(bool) + 268
frame #19: 0x03064adf libobjc.A.dylib`-[NSObject release] + 25
frame #20: 0x039aede0 CoreFoundation`CFRelease + 272
frame #21: 0x03ab67ce CoreFoundation`-[__NSDictionaryI dealloc] + 126
frame #22: 0x03063692 libobjc.A.dylib`objc_object::sidetable_release(bool) + 268
frame #23: 0x03062e81 libobjc.A.dylib`objc_release + 49
frame #24: 0x03063ce7 libobjc.A.dylib`(anonymous namespace)::AutoreleasePoolPage::pop(void*) + 537
frame #25: 0x039cea98 CoreFoundation`_CFAutoreleasePoolPop + 24
frame #26: 0x039d37f3 CoreFoundation`__CFRunLoopRun + 1971
frame #27: 0x039d2bf3 CoreFoundation`CFRunLoopRunSpecific + 467
frame #28: 0x039d2a0b CoreFoundation`CFRunLoopRunInMode + 123
frame #29: 0x03c87a27 GraphicsServices`GSEventRunModal + 192
frame #30: 0x03c8784e GraphicsServices`GSEventRun + 104
frame #31: 0x0093ff0b UIKit`UIApplicationMain + 1225
frame #32: 0x0001eecd MyDog`main(argc=1, argv=0xbfffeeb0) + 141 at main.m:11
I don't know how to debug this when the EXC_BAD_ACCESS is not directly caused by my code. Has anyone had such a problem? Thanks
UPDATE:
I also tried the "Zombies" Instruments preset but it just stopped without giving me any information.
Just ran into same problem. Your UICollectionView is still querying after you popped out the navigation controller. Add the following to the controller class which contains your UICollectionView
- (void)dealloc
{
_collectionView.dataSource = nil;
_collectionView.delegate = nil;
_collectionView = nil;
}
Try setting the .collectionViewLayout=nil in your dealloc method

Resources