Repository: SwiftKickMobile/SwiftMessages

Issue #348: Crash in installMaskingView
Created: 2019-09-25T08:27:25Z
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.).

Duplicate issue #367: Crash: Fatal Exception: NSGenericException
Created: 2019-12-16T10:54:18Z
Seeing this crash on recent releases. Details Below.
Crash Description:
Unable to activate constraint with anchors <NSLayoutYAxisAnchor:0x1049d7540 "SwiftMessages.MaskingView:0x10cd1ffe0.bottom"> and <NSLayoutYAxisAnchor:0x1049d2bf0 "UITabBar:0x10a4e3a00.top"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.
Stack trace:

Fatal Exception: NSGenericException
0  CoreFoundation                 0x18283ad8c __exceptionPreprocess
1  libobjc.A.dylib                0x1819f45ec objc_exception_throw
2  CoreFoundation                 0x18283ac6c -[NSException initWithCoder:]
3  Foundation                     0x183186c5c -[NSLayoutConstraint _setActive:mutuallyExclusiveConstraints:]
4  SwiftMessages                  0x103963b04 installMaskingView #1 (containerView:) in Presenter.install() (Presenter.swift:351)
5  SwiftMessages                  0x1039632ac Presenter.install() (Presenter.swift:417)
6  SwiftMessages                  0x103960dd4 Presenter.show(completion:) (Presenter.swift:116)
7  SwiftMessages                  0x10396a720 closure #1 in SwiftMessages.dequeueNext() (SwiftMessages.swift:560)
8  SwiftMessages                  0x10395c38c thunk for @escaping @callee_guaranteed () -> () ()

Closing comment (2019-12-16T15:28:21Z): This is a duplicate of #348.
So far nobody has provided reproduction steps, so I there's not much I can do. If you can help me reproduce, I'll take a look.