Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SnapKit Crash in iOS 16.1 #764

Open
LeeZhe opened this issue Oct 27, 2022 · 17 comments
Open

SnapKit Crash in iOS 16.1 #764

LeeZhe opened this issue Oct 27, 2022 · 17 comments

Comments

@LeeZhe
Copy link

LeeZhe commented Oct 27, 2022

libobjc.A.dylib
objc_release + 8
1
CoreAutoLayout
0x00000001efda0000 + 46480
2

_$sSo18NSLayoutConstraintC4item9attribute9relatedBy6toItemAD10multiplier8constantAByp_So0A9AttributeVSo0A8RelationVypSgAJ12CoreGraphics7CGFloatVAPtcfCTO + 340
3 _$s7SnapKit10ConstraintC4from2to8relation14sourceLocation5label10multiplier8constant8priorityAcA0C4ItemC_AmA0C8RelationOSS_SutSSSgAA0C16MultiplierTarget_pAA0c8ConstantP0_pAA0c8PriorityP0_ptcfc + 1024
4

$s7SnapKit21ConstraintDescriptionC10constraintAA0C0CSgvgAGyXEfU + 376
5

_$s7SnapKit21ConstraintDescriptionC10constraintAA0C0CSgvg + 40
6

_$s7SnapKit15ConstraintMakerC18prepareConstraints4item7closureSayAA0C0CGAA06LayoutC4Item_p_yACXEtFZTf4enn_nSo6UIViewC_Tg5 + 264
7

_$s7SnapKit15ConstraintMakerC15makeConstraints4item7closureyAA06LayoutC4Item_p_yACXEtFZTf4enn_nSo13UILayoutGuideC_Tg5Tm + 24

@LeeZhe
Copy link
Author

LeeZhe commented Oct 27, 2022

sumupButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(12)
make.centerY.equalToSuperview()
make.width.equalTo(48)
make.height.equalTo(20)
}

@LeeZhe
Copy link
Author

LeeZhe commented Oct 29, 2022

@LeeZhe
Copy link
Author

LeeZhe commented Oct 29, 2022

16.1 AutoLayout crash。does anyone met?

@colinta
Copy link
Contributor

colinta commented Oct 29, 2022

@LeeZhe There’s not enough here to recreate the bug - if you could share a project, or more of the relevant code, maybe someone could take a look.

@LeeZhe
Copy link
Author

LeeZhe commented Oct 29, 2022

@LeeZhe There’s not enough here to recreate the bug - if you could share a project, or more of the relevant code, maybe someone could take a look.

@colinta
we find iOS 16.1 will crash when use spanKit autoLayout

0 libobjc.A.dylib objc_release + 8

1 CoreAutoLayout 0x00000001f2dd3000 + 46480

2 xxxApp _$sSo18NSLayoutConstraintC4item9attribute9relatedBy6toItemAD10multiplier8constantAByp_So0A9AttributeVSo0A8RelationVypSgAJ12CoreGraphics7CGFloatVAPtcfCTO + 336

3 xxxApp _$s7SnapKit10ConstraintC4from2to8relation14sourceLocation5label10multiplier8constant8priorityAcA0C4ItemC_AmA0C8RelationOSS_SutSSSgAA0C16MultiplierTarget_pAA0c8ConstantP0_pAA0c8PriorityP0_ptcfc + 1012

4 xxxApp _$s7SnapKit21ConstraintDescriptionC10constraintAA0C0CSgvgAGyXEfU_ + 376

5 xxxApp _$s7SnapKit21ConstraintDescriptionC10constraintAA0C0CSgvg + 40

6 xxxApp _$s7SnapKit15ConstraintMakerC18prepareConstraints4item7closureSayAA0C0CGAA06LayoutC4Item_p_yACXEtFZTf4enn_nSo6UIViewC_Tg5 + 276

7 xxxApp
_$s7SnapKit15ConstraintMakerC15makeConstraints4item7closureyAA06LayoutC4Item_p_yACXEtFZTf4enn_nSo13UILayoutGuideC_Tg5Tm + 24

The above is the crash stack information, but the normal layout is used. The system crash method of 0x00000001f2dd3000 + 46480 through reverse analysis is

+(int)constraintWithItem:(int)arg2 attribute:(int)arg3 relatedBy:(int)arg4 toItem:(int)arg5 attribute:(int)arg6 multiplier:(id)arg7 constant:(id)arg8 {
  r31 = r31 - 0x70;
  var_40 = d9;
  stack[-72] = d8;
  var_30 = r24;
  stack[-56] = r23;
  var_20 = r22;
  stack[-40] = r21;
  var_10 = r20;
  stack[-24] = r19;
  saved_fp = r29;
  stack[-8] = r30;
  d8 = d1;
  d9 = d0;
  r19 = arg6;
  r20 = arg5;
  _ResolveConstraintArguments(&stack[-88], &var_50, &stack[-104], &var_60);
  loc_1a7e019a0(arg0);
  loc_1a7e018e0();
  r0 = loc_1a7e018f0();
  r21 = r0;
  *(int32_t *)(r0 + 0x42) = *(int32_t *)(r0 + 0x42) | 0x40;
  _objc_msgSend$_setFirstItem:attribute:();
  _objc_msgSend$_setRelation:();
  if (d9 != 0x0 && r20 != 0x0) {
      _objc_msgSend$_setMultiplier:();
      _objc_msgSend$_setSecondItem:attribute:();
  }
  _objc_msgSend$setConstant:();
  _ConstraintDidPerformInitialSetup(r21);
  r0 = r21;
  return r0;
}

and the project example code is

@objc private lazy dynamic var sumupButton: UIButton = {
        let button = UIButton()
        button.setTitle("example", for: .normal)
        button.titleLabel?.font = UIFont.pingFangSC(kind: .medium, fontSize: 14)
        button.setTitleColor(UIColor.red, for: .normal)
        button.setTitleColor(UIColor.black, for: .selected)
        button.isSelected = true
        button.setContentHuggingPriority(UILayoutPriority.defaultHigh, for: NSLayoutConstraint.Axis.horizontal)
        button.addTarget(self, action: #selector(sumupButttonClick), for: .touchUpInside)
        return button
}()

contentView.addSubView(sumupButton)
sumupButton.snp.makeConstraints { make in
        make.left.equalToSuperview().offset(12)
        make.centerY.equalToSuperview()
        make.width.equalTo(48)
        make.height.equalTo(20)
}

@robertjpayne
Copy link
Member

@LeeZhe what is the superview of contentView? SnapKit (and autolayout) typically add constraints to the most common ancestor of two views involved in a constraint.

@LeeZhe
Copy link
Author

LeeZhe commented Nov 1, 2022

@LeeZhe what is the superview of contentView? SnapKit (and autolayout) typically add constraints to the most common ancestor of two views involved in a constraint.

@robertjpayne the superview of contentView is collectionViewCell view, i'm not sure equalToSuperview is the crash reason, you can see the crash stack.

@LeeZhe LeeZhe changed the title equalToSuperview Crash in iOS 16.1 SnapKit Crash in iOS 16.1 Nov 1, 2022
@robertjpayne
Copy link
Member

@LeeZhe unfortunate the stack trace isn't much information. Do you have more coming from Xcode in terms of stack variables or any fatal messages in the console log?

Typically crashes are caused because there is no common parent to attach the constraints to, or something isn't in the view hierarchy.

SnapKit issues fatalError(...) for these because it's a at-code-time non recoverable error that should be fixed.

You could try altering your view setup from:

- view
    - contentView
        - sumupButton

To

- view
    - contentView
        - containerView <--- (add this view, and in UICollectionViewCell layoutSubviews make it the same size as contentView)
            - sumupButton

Worth a shot to see if its related to the superview.

@xwlxwl
Copy link

xwlxwl commented Nov 2, 2022

@LeeZhe unfortunate the stack trace isn't much information. Do you have more coming from Xcode in terms of stack variables or any fatal messages in the console log?

Typically crashes are caused because there is no common parent to attach the constraints to, or something isn't in the view hierarchy.

SnapKit issues fatalError(...) for these because it's a at-code-time non recoverable error that should be fixed.

You could try altering your view setup from:

- view
    - contentView
        - sumupButton

To

- view
    - contentView
        - containerView <--- (add this view, and in UICollectionViewCell layoutSubviews make it the same size as contentView)
            - sumupButton

Cerel ant ayeut •(NSLavounConstraint constralnewithitemieftribute relafed0 ytellamateriteitaimaltipld

Worth a shot to see if its related to the superview.
I have the same crash stack

@LOVEY9527
Copy link

LOVEY9527 commented Nov 21, 2022

I have the same Crash stack,How to fix?

@LeeZhe
Copy link
Author

LeeZhe commented Nov 22, 2022

@robertjpayne how to fix the issue? iOS 16.1 16.2 has crash occasionally.
the stack is
image

@robertjpayne
Copy link
Member

I can't reproduce this crash so it's hard for me to comment here. Instead of using equalToSuperview what if you do equalTo(explicitView) and see if it crashes?

It seems like superview is being a bit buggy with collection views?

@LOVEY9527
Copy link

LOVEY9527 commented Dec 21, 2022

It seems ok to use equalTo(explicitView) instead of equalToSuperview,but I don‘t understand why.
Will you fix this crash in the next version?

@StarSkyK
Copy link

StarSkyK commented Feb 7, 2023

I have the same Crash , help

@xwlxwl
Copy link

xwlxwl commented Mar 2, 2023

I have the same Crash , help
Have you solved it now?

@LeeZhe
Copy link
Author

LeeZhe commented Mar 30, 2023

I have the same Crash , help

@LOVEY9527 I have added your QQ,by your email,the crash has sharp decline about 3.20, can you accept by friend Invitation

@yxsufaniOS
Copy link

I have the same Crash , help

@LOVEY9527 I have added your QQ,by your email,the crash has sharp decline about 3.20, can you accept by friend Invitation

Have you solved it now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants