gpt4 book ai didi

ios - 什么样的事情会导致 viewWillLayoutSubviews 在后台线程中运行?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:38:37 24 4
gpt4 key购买 nike

我在我的应用程序中检测到罕见的崩溃。堆栈跟踪没有帮助。它与我的代码没有直接关系:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSAttributeDictionary textContainerForAttributedString:containerSize:lineFragmentPadding:]: unrecognized selector sent to instance 0x1b8d89c0'

Last Exception Backtrace:
0 CoreFoundation 0x2e23bfd3 __exceptionPreprocess + 131
1 libobjc.A.dylib 0x38ab2ccf objc_exception_throw + 38
2 CoreFoundation 0x2e23f967 -[NSObject(NSObject) doesNotRecognizeSelector:] + 202
3 CoreFoundation 0x2e23e253 ___forwarding___ + 706
4 CoreFoundation 0x2e18d7f8 __forwarding_prep_0___ + 24
5 UIFoundation 0x35e77a25 __NSStringDrawingEngine + 12204
6 UIFoundation 0x35e749a7 -[NSString(NSExtendedStringDrawing) drawWithRect:options:attributes:context:] + 150
7 UIKit 0x30a70d21 -[UILabel _drawTextInRect:baselineCalculationOnly:] + 4224
8 UIKit 0x30ad7009 -[UILabel drawTextInRect:] + 500
9 UIKit 0x30ad6e0b -[UILabel drawRect:] + 78
10 UIKit 0x30ad6da5 -[UIView(CALayerDelegate) drawLayer:inContext:] + 372
11 QuartzCore 0x307042c1 -[CALayer drawInContext:] + 100
12 QuartzCore 0x306ede3f CABackingStoreUpdate_ + 1854
13 QuartzCore 0x307c8d6d ___ZN2CA5Layer8display_Ev_block_invoke + 52
14 QuartzCore 0x306ed6f3 x_blame_allocations + 82
15 QuartzCore 0x306ed39b CA::Layer::display_() + 1106
16 QuartzCore 0x306d103d CA::Layer::display_if_needed(CA::Transaction*) + 208
17 QuartzCore 0x306d0cd5 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
18 QuartzCore 0x306d06df CA::Context::commit_transaction(CA::Transaction*) + 230
19 QuartzCore 0x306d04ef CA::Transaction::commit() + 314
20 QuartzCore 0x306fda83 CA::Transaction::release_thread(void*) + 162
21 libsystem_pthread.dylib 0x390dd68d _pthread_tsd_cleanup + 164
22 libsystem_pthread.dylib 0x390dd40b _pthread_exit + 86
23 libsystem_pthread.dylib 0x390de17d pthread_exit + 28
24 Foundation 0x2eb7846f +[NSThread exit] + 10
25 Foundation 0x2ec24a7d __NSThread__main__ + 1092
26 libsystem_pthread.dylib 0x390de919 _pthread_body + 140
27 libsystem_pthread.dylib 0x390de88b _pthread_start + 102
28 libsystem_pthread.dylib 0x390dcaa4 thread_start + 8

因此,我尝试添加更多调试信息以了解有关崩溃的更多信息。我可以找到 viewWillLayoutSubviews 的踪迹。它在后台被调用。如果我检测到它在后台,我可以退出该功能。但这是一个肮脏的黑客。我想通过阻止“things”在后台线程中调用应用程序 viewWillLayoutSubviews 来正确修复它。

我还没有找到那些“东西”,因为堆栈跟踪没有帮助。

frame #1: 0x32946d16 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 314
frame #2: 0x325c462a QuartzCore`-[CALayer layoutSublayers] + 142
frame #3: 0x325bfe3a QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 350
frame #4: 0x325bfccc QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
frame #5: 0x325bf6de QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 230
frame #6: 0x325bf4ee QuartzCore`CA::Transaction::commit() + 314
frame #7: 0x325eca82 QuartzCore`CA::Transaction::release_thread(void*) + 162
frame #8: 0x3af0568c libsystem_pthread.dylib`_pthread_tsd_cleanup + 164
frame #9: 0x3af0540a libsystem_pthread.dylib`_pthread_exit + 86
frame #10: 0x3af0617c libsystem_pthread.dylib`pthread_exit + 28
frame #11: 0x30a6746e Foundation`+[NSThread exit] + 10
frame #12: 0x30b13a7c Foundation`__NSThread__main__ + 1092
frame #13: 0x3af06918 libsystem_pthread.dylib`_pthread_body + 140
frame #14: 0x3af0688a libsystem_pthread.dylib`_pthread_start + 102`

那些“东西”可以是什么?

最佳答案

当你在后台调用一些必须在主线程上运行的东西时,就会发生这种崩溃。

找到确切的线路几乎是不可能的。我发现结果中有很多 NSLog 行和 [NSThread isMainThread] 行。

调用 UI 元素上的几乎所有内容(尤其是那些需要计算/更改大小的元素,触发 viewWillLayoutSubviews。在我的例子中,它是 UIImageViews 和 UILabels。

如果您找不到在后台进行 UI 更新的位置,请检查您是否在后台发布了 NSNotification

关于ios - 什么样的事情会导致 viewWillLayoutSubviews 在后台线程中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25590226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com