5

I'm getting this crash on crashlytics (fabric), but unable to reproduce it or understand its origin based on the traceback.

Crashed: com.apple.main-thread
0  MyApp                          0x1001080a0 MyViewController.viewWillAppear(Bool) -> () (MyViewController.swift:135)
1  MyApp                          0x1001080d0 @objc MyViewController.viewWillAppear(Bool) -> () (MyViewController.swift)
2  UIKit                          0x18868bbf4 -[UIViewController _setViewAppearState:isAnimating:] + 632
3  UIKit                          0x18868b964 -[UIViewController __viewWillAppear:] + 156
4  UIKit                          0x1888101d4 -[UINavigationController _startCustomTransition:] + 1144
5  UIKit                          0x18872ab78 -[UINavigationController _startDeferredTransitionIfNeeded:] + 676
6  UIKit                          0x18872a7e0 -[UINavigationController __viewWillLayoutSubviews] + 64
7  UIKit                          0x18872a744 -[UILayoutContainerView layoutSubviews] + 188
8  UIKit                          0x18867107c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1200
9  QuartzCore                     0x185861274 -[CALayer layoutSublayers] + 148
10 QuartzCore                     0x185855de8 CA::Layer::layout_if_needed(CA::Transaction*) + 292
11 QuartzCore                     0x185855ca8 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 32
12 QuartzCore                     0x1857d134c CA::Context::commit_transaction(CA::Transaction*) + 252
13 QuartzCore                     0x1857f83ac CA::Transaction::commit() + 504
14 UIKit                          0x1888f2524 _UIApplicationFlushRunLoopCATransactionIfTooLate + 172
15 UIKit                          0x188e689f8 __handleEventQueue + 4916
16 UIKit                          0x188e68b9c __handleHIDEventFetcherDrain + 148
17 CoreFoundation                 0x1824f142c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
18 CoreFoundation                 0x1824f0d9c __CFRunLoopDoSources0 + 540
19 CoreFoundation                 0x1824ee9a8 __CFRunLoopRun + 744
20 CoreFoundation                 0x18241eda4 CFRunLoopRunSpecific + 424
21 GraphicsServices               0x183e88074 GSEventRunModal + 100
22 UIKit                          0x1886d9058 UIApplicationMain + 208
23 MyApp                          0x1009052fc main (AppDelegate.swift:16)
24 libdyld.dylib                  0x18142d59c start + 4

The code in MyViewController:

@IBOutlet weak var someConstraint: NSLayoutConstraint!
@IBOutlet weak var button: UIButton! 
let minHeight: CGFloat = 2.0
let cValue: CGFloat = 32.0

override func viewWillAppear(_ animated: Bool) {
  super.viewWillAppear(animated)

  let aValue = button.frame.origin.y - UIApplication.shared.statusBarFrame.height
  let bValue = button.bounds.height + minHeight
  someConstraint.constant = max(aValue - bValue, cValue) // --> Crash here, line 135
}

Update: SomeConstraint is not nil.

Forge
  • 6,538
  • 6
  • 44
  • 64
  • 2
    Have you checked that `someConstraint` is properly connected in Interface Builder, and not `nil`? – Martin R Jun 01 '17 at 12:39
  • Yes, it's not nil @MartinR – Forge Jun 01 '17 at 13:19
  • 1
    I think you need to provide more info. Check the button too whether its nil or not. Print the max(aValue, bValue and cValue) result. Also call `self.view.layoutIfNeeded` at last. Just a weird try, write this code in `viewDidAppear` as the view is not fully loaded till `viewWillAppear` – Rajan Maheshwari Jun 01 '17 at 14:32
  • you shouldn't manipulate constraints in `viewWillApper`, you should user `viewDidLayoutSubviews` instead, and create condition to set it once – JuicyFruit Jun 02 '17 at 08:04
  • turn on Zombie Objects and try again - u will see the reason or try to add symbolic breakPoint -> http://blog.manbolo.com/2012/01/23/xcode-tips-1-break-on-exceptions – hbk Jul 28 '17 at 07:35
  • Remove the "weak" from some constraint. – Krešimir Prcela Feb 15 '19 at 10:26
  • have you resolve the issue? – orium Feb 17 '19 at 11:10
  • Have you checked all other background threads( `CALayer` animation can be called there) ? – olha Feb 17 '19 at 19:54

0 Answers0