My App always encounter with CoreAutoLayout invade
My SnapKit layout constraint as follow:
popBgView.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.leading.equalTo(assistantTeacherView.snp.trailing).offset(.isiPad ? -50 : -40)
if TTLGlobalConstants.isCompactScreen320 {
make.width.lessThanOrEqualTo(300)
} else {
let widthRatio = .isiPad ? 494.0 / 1024.0 : 434.0 / 812.0
make.width.lessThanOrEqualTo(TTLGlobalConstants.screenWidth * widthRatio)
}
bubbleViewRightConstraint = make.trailing.equalToSuperview().constraint
}
.....
popBgView.addSubview(functionView)
msgLabel.snp.remakeConstraints { make in
make.leading.equalToSuperview().inset(Metric.msgLabelHorizantalInset)
make.centerY.equalToSuperview()
make.trailing.lessThanOrEqualToSuperview().inset(Metric.msgLabelHorizantalInset)
make.top.equalTo(Metric.msgLabelVerticalInset)
}
functionView.snp.makeConstraints { make in
make.leading.equalTo(msgLabel.snp.trailing).offset(Metric.msgLabelFunctionSpacing)
make.centerY.equalToSuperview()
make.trailing.equalToSuperview().offset(-Metric.msgLabelHorizantalInset)
}
msgLabel and functionView superview is popBgView
However, when I try remove from superview for functionView, There is low probability crash:
OS Version: iOS 16.1.1 (20B101) Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: SEGV_NOOP Crashed Thread: 0
Application Specific Information: Exception 1, Code 1, Subcode 14967683541490370463 > KERN_INVALID_ADDRESS at 0xcfb7e4e0f8fe879f.
Thread 0 Crashed:
0 CoreAutoLayout 0x382555f44 -[NSISEngine positiveErrorVarForBrokenConstraintWithMarker:errorVar:]
1 CoreAutoLayout 0x382555e9c -[NSISEngine positiveErrorVarForBrokenConstraintWithMarker:errorVar:]
2 CoreAutoLayout 0x3825557e4 -[NSISEngine removeConstraintWithMarker:]
3 CoreAutoLayout 0x382555198 -[NSLayoutConstraint _removeFromEngine:]
4 UIKitCore 0x34d87961c __57-[UIView _switchToLayoutEngine:]_block_invoke
5 CoreAutoLayout 0x382556e8c -[NSISEngine withBehaviors:performModifications:]
6 UIKitCore 0x34d8a1c38 -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]
7 UIKitCore 0x34d7f01b0 __57-[UIView _switchToLayoutEngine:]_block_invoke_2
8 UIKitCore 0x34d879770 __57-[UIView _switchToLayoutEngine:]_block_invoke
9 CoreAutoLayout 0x382556e8c -[NSISEngine withBehaviors:performModifications:]
10 UIKitCore 0x34d8a1c38 -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]
11 UIKitCore 0x34d8a1848 __45-[UIView _postMovedFromSuperview:]_block_invoke
12 UIKitCore 0x34e7ff8d0 -[UIView _postMovedFromSuperview:]
13 UIKitCore 0x34d85e3c8 __UIViewWasRemovedFromSuperview
14 UIKitCore 0x34d85b1a4 -[UIView(Hierarchy) removeFromSuperview]
15 Collie-iPad 0x203001550 [inlined] InClassAssistantView.functionView.didset (InClassAssistantView.swift:105)