SnapKit / Masonry

Harness the power of AutoLayout NSLayoutConstraints with a simplified, chainable and expressive syntax. Supports iOS and OSX Auto Layout
MIT License
18.05k stars 3.14k forks source link

Constraint with centerX/centerY seems lead to random crash #474

Open thorfei opened 7 years ago

thorfei commented 7 years ago

New Issue Checklist

🚫 If this template is not filled out your issue will be closed with no comment. 🚫

Issue Info

Info Value
Platform ios
Platform Version 7.0/8.0/9.0
Masonry Version 1.0.2
Integration Method cocoapods

Issue Description

Our app got random with using centerY or centerX attribute like below code snippets. And we try don't use them, no crash collected. We read the masonry source code, and have no idea about the crash reason. This random crash is hard to reproduce because of memory issue.

Anybody else met the same crash let me know!

[checkIcon makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(container.centerY); // random crash
        make.left.equalTo(container.left).offset(15.0f);
        make.width.and.height.equalTo(20.0f);
 }];

 [textLabel makeConstraints:^(MASConstraintMaker *make) {
    __strong typeof(wself) self = wself;
    make.centerY.equalTo(self.centerY); // random crash
    make.leading.equalTo(self.leading).offset(15);
}];

[button makeConstraints:^(MASConstraintMaker *make) {
    make.centerY.equalTo(nicknameTextField.centerY); // random crash
    make.width.height.equalTo(17.0f);
    make.right.equalTo(self).offset(-12.5);
}];

[containerView makeConstraints:^(MASConstraintMaker *make) {
    make.centerX.equalTo(contentView.centerX).offset(2); //random crash
    make.centerY.equalTo(contentView.centerY);
}];

Crash stack like this

#0. Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x3954e608 objc_retain + 7
1  xxx                            0x1c31ed __30-[YYView layout]_block_invoke (PDDChatListLoginView.m:66)
2  xxx                            0x4479cb -[UIView(MASAdditions) mas_makeConstraints:] (View+MASAdditions.m:17)
3  xxx                            0x1c2fb5 -[YYView layout] (YYView.m:64)
4  xxx                            0x1c2ab3 -[YYView initWithFrame:] (YYView.m:32)