iOS iPad GUI 启动时死锁。挂在启动画面上

发布于 2024-09-14 16:17:15 字数 3860 浏览 6 评论 0原文

我的 iPad 应用程序有时会在启动时挂起。看起来主线程与另一个线程陷入僵局,但不知道为什么。关于造成此问题的原因以及如何调试此问题有什么想法吗?

仅供参考,我的应用程序作为一个 splitview 控制器启动,左侧有一个列表视图,右侧有一个网络视图。如果我以隐藏列表视图的纵向模式启动,则不会出现问题。另外,如果我在不在主线程上时禁用单元格的渲染,则应用程序不会挂起,但单元格显示为黑色矩形。

谢谢!

这是我的主线。该堆栈上的所有代码都是 Apple 框架...

#0  0x971c0142 in semaphore_wait_signal_trap ()
#1  0x971c5c06 in pthread_mutex_lock ()
#2  0x02685903 in CGFontCacheLock ()
#3  0x02685869 in CGGlyphLockLockGlyphBitmaps ()
#4  0x0a90bb5b in ripc_RenderGlyphs ()
#5  0x0a9199f8 in ripc_DrawGlyphs ()
#6  0x0268464c in draw_glyphs ()
#7  0x02683e97 in CGContextShowGlyphsWithAdvances ()
#8  0x035aafba in WebCore::Font::drawGlyphs ()
#9  0x035aaaf5 in WebCore::Font::drawGlyphBuffer ()
#10 0x035aa81a in WebCore::Font::drawSimpleText ()
#11 0x035aa4c0 in drawAtPoint ()
#12 0x035a9d5c in -[NSString(WebStringDrawing) _web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:] ()
#13 0x0043f632 in -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:letterSpacing:includeEmoji:] ()
#14 0x0043f325 in -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:] ()
#15 0x0055ba70 in -[UILabel _drawTextInRect:baselineCalculationOnly:] ()
#16 0x00559178 in -[UILabel drawTextInRect:] ()
#17 0x0045418f in -[UIView(CALayerDelegate) drawLayer:inContext:] ()
#18 0x02a708d2 in -[CALayer drawInContext:] ()
#19 0x02a704b0 in backing_callback ()
#20 0x02a6fd52 in CABackingStoreUpdate ()
#21 0x02a6f01d in -[CALayer _display] ()
#22 0x02a6eac7 in CALayerDisplayIfNeeded ()
#23 0x02a609e1 in CA::Context::commit_transaction ()
#24 0x02a60732 in CA::Transaction::commit ()
#25 0x00427556 in -[UIApplication _reportAppLaunchFinished] ()
#26 0x0042dd3e in -[UIApplication handleEvent:withNewEvent:] ()
#27 0x004294f7 in -[UIApplication sendEvent:] ()
#28 0x004311d8 in _UIApplicationHandleEvent ()
#29 0x033f817c in PurpleEventCallback ()
#30 0x02bec89c in CFRunLoopRunSpecific ()
#31 0x02beb8a8 in CFRunLoopRunInMode ()
#32 0x00427221 in -[UIApplication _run] ()
#33 0x0042f372 in UIApplicationMain ()

另一个线程在我的列表视图中渲染单元格。 MyFancyPantsCell& ABTableViewCellView 是我的课程。

#0  0x971c0142 in semaphore_wait_signal_trap ()
#1  0x971c5c06 in pthread_mutex_lock ()
#2  0x02685903 in CGFontCacheLock ()
#3  0x02685869 in CGGlyphLockLockGlyphBitmaps ()
#4  0x0a90bb5b in ripc_RenderGlyphs ()
#5  0x0a9199f8 in ripc_DrawGlyphs ()
#6  0x0268464c in draw_glyphs ()
#7  0x02683e97 in CGContextShowGlyphsWithAdvances ()
#8  0x035aafba in WebCore::Font::drawGlyphs ()
#9  0x035aaaf5 in WebCore::Font::drawGlyphBuffer ()
#10 0x035aa81a in WebCore::Font::drawSimpleText ()
#11 0x035aa4c0 in drawAtPoint ()
#12 0x035a9d5c in -[NSString(WebStringDrawing) _web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:] ()
#13 0x0043f632 in -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:letterSpacing:includeEmoji:] ()
#14 0x0043f381 in -[NSString(UIStringDrawing) drawAtPoint:withFont:] ()
#15 0x000635ec in -[SymbolCellPainter drawContentView:selected:editing:frame:] 
#16 0x000452d0 in -[MyFancyPantsCell drawContentView:] 
#17 0x00044624 in -[ABTableViewCellView drawRect:] 
#18 0x0045418f in -[UIView(CALayerDelegate) drawLayer:inContext:] ()
#19 0x02a708d2 in -[CALayer drawInContext:] ()
#20 0x02a704b0 in backing_callback ()
#21 0x02a6fd52 in CABackingStoreUpdate ()
#22 0x02a6f01d in -[CALayer _display] ()
#23 0x02a6eac7 in CALayerDisplayIfNeeded ()
#24 0x02a609e1 in CA::Context::commit_transaction ()
#25 0x02a60732 in CA::Transaction::commit ()
#26 0x02a9e04f in CA::Transaction::release_thread ()
#27 0x971f61e3 in _pthread_tsd_cleanup ()
#28 0x971f5df6 in _pthread_exit ()
#29 0x00183bf2 in +[NSThread exit] ()
#30 0x00183b5b in __NSThread__main__ ()
#31 0x971ed81d in _pthread_start ()
#32 0x971ed6a2 in thread_start ()

My iPad app hangs on startup sometimes. It looks like the main thread is getting deadlocked with another thread but not sure why. Any ideas on what's causing this and how to debug this?

FYI my app starts as a splitview controller with a listview on the left and a webview on the right. If I start in portrait mode with the list view hidden the problem doesn't occur. Also, if I disable renderig of my cell when not on the main thread the app doesn't hang but the cells appear as black rectangles.

Thanks!

Here's my main thread. All of the code on this stack is Apple framework...

#0  0x971c0142 in semaphore_wait_signal_trap ()
#1  0x971c5c06 in pthread_mutex_lock ()
#2  0x02685903 in CGFontCacheLock ()
#3  0x02685869 in CGGlyphLockLockGlyphBitmaps ()
#4  0x0a90bb5b in ripc_RenderGlyphs ()
#5  0x0a9199f8 in ripc_DrawGlyphs ()
#6  0x0268464c in draw_glyphs ()
#7  0x02683e97 in CGContextShowGlyphsWithAdvances ()
#8  0x035aafba in WebCore::Font::drawGlyphs ()
#9  0x035aaaf5 in WebCore::Font::drawGlyphBuffer ()
#10 0x035aa81a in WebCore::Font::drawSimpleText ()
#11 0x035aa4c0 in drawAtPoint ()
#12 0x035a9d5c in -[NSString(WebStringDrawing) _web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:] ()
#13 0x0043f632 in -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:letterSpacing:includeEmoji:] ()
#14 0x0043f325 in -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:] ()
#15 0x0055ba70 in -[UILabel _drawTextInRect:baselineCalculationOnly:] ()
#16 0x00559178 in -[UILabel drawTextInRect:] ()
#17 0x0045418f in -[UIView(CALayerDelegate) drawLayer:inContext:] ()
#18 0x02a708d2 in -[CALayer drawInContext:] ()
#19 0x02a704b0 in backing_callback ()
#20 0x02a6fd52 in CABackingStoreUpdate ()
#21 0x02a6f01d in -[CALayer _display] ()
#22 0x02a6eac7 in CALayerDisplayIfNeeded ()
#23 0x02a609e1 in CA::Context::commit_transaction ()
#24 0x02a60732 in CA::Transaction::commit ()
#25 0x00427556 in -[UIApplication _reportAppLaunchFinished] ()
#26 0x0042dd3e in -[UIApplication handleEvent:withNewEvent:] ()
#27 0x004294f7 in -[UIApplication sendEvent:] ()
#28 0x004311d8 in _UIApplicationHandleEvent ()
#29 0x033f817c in PurpleEventCallback ()
#30 0x02bec89c in CFRunLoopRunSpecific ()
#31 0x02beb8a8 in CFRunLoopRunInMode ()
#32 0x00427221 in -[UIApplication _run] ()
#33 0x0042f372 in UIApplicationMain ()

And another thread rendering a cell in my list view. MyFancyPantsCell & ABTableViewCellView are my classes.

#0  0x971c0142 in semaphore_wait_signal_trap ()
#1  0x971c5c06 in pthread_mutex_lock ()
#2  0x02685903 in CGFontCacheLock ()
#3  0x02685869 in CGGlyphLockLockGlyphBitmaps ()
#4  0x0a90bb5b in ripc_RenderGlyphs ()
#5  0x0a9199f8 in ripc_DrawGlyphs ()
#6  0x0268464c in draw_glyphs ()
#7  0x02683e97 in CGContextShowGlyphsWithAdvances ()
#8  0x035aafba in WebCore::Font::drawGlyphs ()
#9  0x035aaaf5 in WebCore::Font::drawGlyphBuffer ()
#10 0x035aa81a in WebCore::Font::drawSimpleText ()
#11 0x035aa4c0 in drawAtPoint ()
#12 0x035a9d5c in -[NSString(WebStringDrawing) _web_drawAtPoint:forWidth:withFont:ellipsis:letterSpacing:includeEmoji:] ()
#13 0x0043f632 in -[NSString(UIStringDrawing) drawAtPoint:forWidth:withFont:lineBreakMode:letterSpacing:includeEmoji:] ()
#14 0x0043f381 in -[NSString(UIStringDrawing) drawAtPoint:withFont:] ()
#15 0x000635ec in -[SymbolCellPainter drawContentView:selected:editing:frame:] 
#16 0x000452d0 in -[MyFancyPantsCell drawContentView:] 
#17 0x00044624 in -[ABTableViewCellView drawRect:] 
#18 0x0045418f in -[UIView(CALayerDelegate) drawLayer:inContext:] ()
#19 0x02a708d2 in -[CALayer drawInContext:] ()
#20 0x02a704b0 in backing_callback ()
#21 0x02a6fd52 in CABackingStoreUpdate ()
#22 0x02a6f01d in -[CALayer _display] ()
#23 0x02a6eac7 in CALayerDisplayIfNeeded ()
#24 0x02a609e1 in CA::Context::commit_transaction ()
#25 0x02a60732 in CA::Transaction::commit ()
#26 0x02a9e04f in CA::Transaction::release_thread ()
#27 0x971f61e3 in _pthread_tsd_cleanup ()
#28 0x971f5df6 in _pthread_exit ()
#29 0x00183bf2 in +[NSThread exit] ()
#30 0x00183b5b in __NSThread__main__ ()
#31 0x971ed81d in _pthread_start ()
#32 0x971ed6a2 in thread_start ()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

叫嚣ゝ 2024-09-21 16:17:15

我看起来您已经创建了另一个线程,例如通过[object PerformSelectorInBackground:@selector(foo) withObject:bar]。在该线程中您可以调用 GUI 方法。您应该使用 [object PerformSelectorOnMainThread:@selector(alpha) withObject:beta waitUntilDone:YES] 调用 GUI 方法(也许创建另一个只包含 GUI 方法的方法并以这种方式调用该方法,而不是这样做20 在主线程上执行选择器)。

所有 GUI 方法都应该在主线程上运行。

I looks like you've created another thread, e.g. via [object performSelectorInBackground:@selector(foo) withObject:bar]. And in that thread you call GUI methods. You should call the GUI methods with [object performSelectorOnMainThread:@selector(alpha) withObject:beta waitUntilDone:YES] (maybe create another method that just contains the GUI methods and call that one this way instead of doing 20 performSelectorOnMainThreads).

All GUI methods should run on the main thread.

暮光沉寂 2024-09-21 16:17:15

您是否在代码中的某处使用 CATransitions ?

Core Animation 支持两种类型的事务:隐式事务和显式事务。当没有活动事务的线程修改层树时,会自动创建隐式事务,并在线程的运行循环下次迭代时自动提交。当应用程序在修改图层树之前向 CATransaction 类发送开始消息并在之后发送提交消息时,就会发生显式事务。

似乎隐式事务可以在后台线程中触发,从那里调用drawRect。
如果主线程中同时进行一些绘图,那么您就有麻烦了。

在这种情况下,[CATransaction begin] / [CATransaction commit] 可能会有所帮助。

Are you using CATransitions somewhere in your code ?

Core Animation supports two types of transactions: implicit transactions and explicit transactions. Implicit transactions are created automatically when the layer tree is modified by a thread without an active transaction and are committed automatically when the thread's run-loop next iterates. Explicit transactions occur when the the application sends the CATransaction class a begin message before modifying the layer tree, and a commit message afterwards.

It seems that implicit transactions can fire in background threads calling drawRect from there.
If there's some drawing going on in the main thread at the same time - you're in trouble.

In this case, [CATransaction begin] / [CATransaction commit] MAY help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文