SwiftMessages: Crash in installMaskingView

Hello 😃

I’ve posted almost 1 year ago in #253 an issue where my app crashed due to autolayout issue. At the time i’ve updated SwiftMessage to 6.0.2 and the crash is still there, but slightly differs from the old one. With SwiftMessage 4.1.4:

Fatal Exception: NSInternalInconsistencyException
Impossible to set up layout with view hierarchy unprepared for constraint.
0  CoreFoundation                 0x1835a2d8c __exceptionPreprocess
1  libobjc.A.dylib                0x18275c5ec objc_exception_throw
2  CoreFoundation                 0x1835a2bf8 +[NSException raise:format:]
3  Foundation                     0x183f92fa0 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4  UIKit                          0x18dcd1f78 __120-[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:]_block_invoke_2
5  UIKit                          0x18d1c29ec -[UIView(UIConstraintBasedLayout) _layoutEngine_didAddLayoutConstraint:roundingAdjustment:mutuallyExclusiveConstraints:]
6  UIKit                          0x18d1c2804 -[UIView(UIConstraintBasedLayout) _tryToAddConstraintWithoutUpdatingConstraintsArray:roundingAdjustment:mutuallyExclusiveConstraints:]
7  UIKit                          0x18d4b1254 __50-[UIView(UIConstraintBasedLayout) addConstraints:]_block_invoke
8  Foundation                     0x183ef1500 -[NSISEngine withBehaviors:performModifications:]
9  UIKit                          0x18d2670cc -[UIView(UIConstraintBasedLayout) addConstraints:]
10 SwiftMessages                  0x104e08dac specialized installMaskingView #1 (containerView:) in Presenter.install() (Presenter.swift:344)
11 SwiftMessages                  0x104e065d0 Presenter.install() (Presenter.swift)
12 SwiftMessages                  0x104e097e4 specialized Presenter.show(completion:) (Presenter.swift:116)
13 SwiftMessages                  0x104e0c3b8 closure #1 in SwiftMessages.dequeueNext() (SwiftMessages.swift:539)
14 SwiftMessages                  0x104e19088 _T0Ieg_IeyB_TR (TopBottomAnimation.swift)
15 libdispatch.dylib              0x182e94aa0 _dispatch_call_block_and_release
16 libdispatch.dylib              0x182e94a60 _dispatch_client_callout
17 libdispatch.dylib              0x182ea165c _dispatch_main_queue_callback_4CF$VARIANT$mp
18 CoreFoundation                 0x18354b070 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
19 CoreFoundation                 0x183548bc8 __CFRunLoopRun
20 CoreFoundation                 0x183468da8 CFRunLoopRunSpecific
21 GraphicsServices               0x18544e020 GSEventRunModal
22 UIKit                          0x18d488758 UIApplicationMain
23 MyApp                          0x1026ff028 main (AppDelegate.swift:28)
24 libdyld.dylib                  0x182ef9fc0 start

With SwiftMessage 6.0.2:


Fatal Exception: NSGenericExceptionUnable to activate constraint with anchors <NSLayoutYAxisAnchor:0x282e77d00 "SwiftMessages.MaskingView:0x108b19e20.bottom"> and <NSLayoutYAxisAnchor:0x282e71e80 "UITabBar:0x108a04ee0.top"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal. Raw Text
--
0 | CoreFoundation | __exceptionPreprocess
1 | libobjc.A.dylib | objc_exception_throw
2 | CoreFoundation | -[NSCache init]
3 | Foundation | -[NSLayoutConstraint _setActive:mutuallyExclusiveConstraints:]
4 | SwiftMessages | <compiler-generated> line 0installMaskingView #1 (containerView:) in Presenter.install()
5 | SwiftMessages | Presenter.swift line 401Presenter.install() + 401
6 | SwiftMessages | <compiler-generated> line 0Presenter.show(completion:)
7 | SwiftMessages | SwiftMessages.swift line 547closure #1 in SwiftMessages.dequeueNext() + 547
8 | SwiftMessages | <compiler-generated> line 0thunk for @escaping @callee_guaranteed () -> ()
9 | libdispatch.dylib | _dispatch_call_block_and_release
10 | libdispatch.dylib | _dispatch_client_callout
11 | libdispatch.dylib | _dispatch_main_queue_callback_4CF$VARIANT$mp
12 | CoreFoundation | __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
13 | CoreFoundation | __CFRunLoopRun
14 | CoreFoundation | CFRunLoopRunSpecific
15 | GraphicsServices | GSEventRunModal
16 | UIKitCore | UIApplicationMain
17 | MyApp | AppDelegate.swift line 28main + 28
18 | libdyld.dylib | start

Here is an example of the way I show a message:

let view = MessageView.viewFromNib(layout: .messageView)
    let buttonTapHandler: ((UIButton ) -> Void)? = { _ in
      SwiftMessages.hideAll()
    }
    let buttonImage = Asset.Common.erroriconsubtlecustom.image
    view.configureContent(title: title, body: body, iconImage: nil, iconText: nil, buttonImage: buttonImage, buttonTitle: nil, buttonTapHandler: buttonTapHandler)
    view.backgroundColor = ColorName.weather.color
    view.titleLabel?.textColor = .white
    view.bodyLabel?.textColor = .white
    view.button?.tintColor = .white
    view.titleLabel?.font = FontFamily.SanFranciscoText.heavy.font(size: 12)
    view.bodyLabel?.numberOfLines = 3
    view.bodyLabel?.font = FontFamily.SanFranciscoText.regular.font(size: 13)
    view.tapHandler = tapHandler

    var config = SwiftMessages.defaultConfig
    config.presentationStyle = .bottom
    config.duration = .forever
    config.interactiveHide = true

    SwiftMessages.show(config: config, view: view)

Messages that seems to crash are presented in theviewDidAppear of a UITabBarViewController subclass, with a UINavigationController as parent of the message

Updating to SwiftMessage 7.0.1 isn’t an option for now as it requires Xcode 11 which I don’t plan to use really soon (bugs, project compatibility, etc.).

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

I’ve managed to reproduce this once on my device:

I have some view controllers that can both show a .bottom aligned SwiftMessage and push another view controller in viewDidAppear

In cases where both happen, and the pushed view controller has .hideBottomBarOnPush = true, sometimes there’s a timing issue that causes this crash. I’m going to make these items mutually exclusive to prevent this issue.