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

ios14.1 崩溃 #133

Open
kzq5 opened this issue Nov 23, 2020 · 12 comments
Open

ios14.1 崩溃 #133

kzq5 opened this issue Nov 23, 2020 · 12 comments

Comments

@kzq5
Copy link

kzq5 commented Nov 23, 2020

作者你好,我这边在bugly上看到有5次crash,2个机型,版本都是ios14.1。如下:

#9 io.flutter.1.raster
NSInternalInconsistencyException

Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.

0 CoreFoundation ___exceptionPreprocess + 216
1 libobjc.A.dylib objc_exception_throw + 56
2 CoreAutoLayout 0x00000001b7dfa000 + 63076
3 CoreAutoLayout 0x00000001b7dfa000 + 62268
4 CoreAutoLayout 0x00000001b7dfa000 + 61084
5 CoreAutoLayout 0x00000001b7dfa000 + 43900
6 UIKitCore -[UIView(Hierarchy) layoutSubviews] + 464
7 我的工程名 -[UIView(LEEAlertExtension) lee_alert_view_layoutSubviews] (LEEAlert.m:1286)
8 我的工程名 -[UIView(SDAutoLayout) sd_layoutSubviews] (UIView+SDAutoLayout.m:1058)
9 UIKitCore -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2464
10 QuartzCore 0x00000001a73f6000 + 1395240
11 QuartzCore 0x00000001a73f6000 + 1421044
12 QuartzCore 0x00000001a73f6000 + 1466896
13 QuartzCore 0x00000001a73f6000 + 730432
14 QuartzCore 0x00000001a73f6000 + 902872
15 QuartzCore 0x00000001a73f6000 + 907656
16 CoreFoundation _CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 32
17 CoreFoundation ___CFRunLoopDoObservers + 604
18 CoreFoundation ___CFRunLoopRun + 960
19 CoreFoundation CFRunLoopRunSpecific + 572
20 Flutter fml::MessageLoopDarwin::Run() (message_loop_darwin.mm:47)
21 Flutter _ZNSt3__114__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEZN3fml6ThreadC1ERKNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEE3$0EEEEEPvSJ (message_loop_impl.cc:96)
22 libsystem_pthread.dylib _pthread_start + 288
23 libsystem_pthread.dylib thread_start + 8

原因就是非主线程调用layoutSubview了,.用的版本是1.4.0,我看了一些issue,有部分跟我类似的crash我看作者已经标注已修复了,能说下之前修复的是什么问题导致的吗?或者帮我看下我这个的crash问题。

我查看了工程中的代码,唯一有一个可能是从flutter中调用一个原生的桥接方法在原生代码中提示了一个弹窗,但是在iso14.1上也没crash。

@kzq5
Copy link
Author

kzq5 commented Nov 23, 2020

图片
看这个崩溃情况感觉像是必现的,同一机型,4次崩溃

@lixiang1994
Copy link
Owner

我只是做了layoutSubviews方法交换 用来更新圆角处理 (如果你通过我的方式设置了圆角, 否则不会做任何事情), 我可以肯定LEEAlert内部无子线程操作, 所以不存在非主线程调用layoutSubview的.

@kzq5
Copy link
Author

kzq5 commented Nov 23, 2020

我只是做了layoutSubviews方法交换 用来更新圆角处理 (如果你通过我的方式设置了圆角, 否则不会做任何事情), 我可以肯定LEEAlert内部无子线程操作, 所以不存在非主线程调用layoutSubview的.

嗯,我知道这个问题并非leealert的bug,只是我想知道之前的issue中类似的crash作者是修复了什么吗?以及现在1.4.3版本对比1.4.0有做相关issue的处理吗

@kzq5
Copy link
Author

kzq5 commented Nov 23, 2020

然后我看是否升级一下最新版本,以及对我猜测的地方做一个处理

@lixiang1994
Copy link
Owner

👌, 版本更新记录在这里https://github.com/lixiang1994/LEEAlert/blob/master/UPDATELOG.md

@lixiang1994
Copy link
Owner

一般之前这类问题 最终都是提问的人自己排查项目代码解决的 😁

@kzq5
Copy link
Author

kzq5 commented Nov 23, 2020

一般之前这类问题 最终都是提问的人自己排查项目代码解决的 😁

好的,那现在只能先升级一下版本,以及对我猜测的地方做一下处理了,谢谢

@lixiang1994
Copy link
Owner

flutter 我不太了解 你可以在有风险的地方 埋个点或者写入日志 看看是不是在主线程

@kzq5
Copy link
Author

kzq5 commented Nov 23, 2020

flutter 我不太了解 你可以在有风险的地方 埋个点或者写入日志 看看是不是在主线程

嗯,那这个issue就先不关了,后边我排查到了问题,再补充一下,供其他人遇到了参考

@LeoFavor1562
Copy link

遇到了同样的问题,错误堆栈一模一样。。。

@XiaolongWang
Copy link

XiaolongWang commented Jan 8, 2021

哎,这个问题排查清楚了。
这是个关联问题,涉及SDWebImage、MBProgressHUD,SDWebImage在下载完成后,会在子线程中调用 MBProgressHUD setProgress方法。
而 MBProgressHUD 1.2.0 更新了setProgress 方法

  • (void)setProgress:(float)progress {
    if (progress != _progress) {
    _progress = progress;
    UIView *indicator = self.indicator;
    if ([indicator respondsToSelector:@selector(setProgress:)]) {
    [(id)indicator setValue:@(self.progress) forKey:@"progress"]; // 在这里操纵了 indicator 。
    }
    }
    }

setProgress 中对 indicator view 做了赋值操作,同时触发 setNeedsDisplay
结局是在子线程中调用了 setNeedsDisplay 进而调用 layoutSubViews 而 crash。

修复这个问题需要在 MBProgressHUD 找到这里 setProgress 方法,做如下修改,即可解决问题。

  • (void)setProgress:(float)progress {
    if (progress != _progress) {
    _progress = progress;
    if ([NSThread isMainThread]) {
    UIView *indicator = self.indicator;
    if ([indicator respondsToSelector:@selector(setProgress:)]) {
    [(id)indicator setValue:@(self.progress) forKey:@"progress"];
    }
    }else{
    dispatch_async(dispatch_get_main_queue(), ^{
    UIView *indicator = self.indicator;
    if ([indicator respondsToSelector:@selector(setProgress:)]) {
    [(id)indicator setValue:@(self.progress) forKey:@"progress"];
    }
    });
    }
    }
    }

@lixiang1994
Copy link
Owner

泪目

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

4 participants