【问题标题】:deleted thread with uncommitted CATransaction not showing source?未提交的 CATransaction 未显示源的已删除线程?
【发布时间】:2014-08-13 14:22:02
【问题描述】:

还有很多关于堆栈溢出的其他条目: CoreAnimation: warning, deleted thread with uncommitted CATransaction 消息并通过启用 CA_DEBUG_TRANSACTIONS 对其进行排序。在我看到的 99% 的其他帖子中,回溯显示了未提交动画的来源(例如,参见 Core Animation Warning: "uncommitted CATransaction",它显示了在 MyApp 中调用的函数)。

就我而言,我已将 CA_DEBUG_TRANSACTIONS 标志设置为 1,然后我得到了回溯,但不幸的是它没有告诉我它来自哪里:

Deallocating
CoreAnimation: warning, deleted thread with uncommitted CATransaction; created by:
0   QuartzCore                          0x00007fff95f8c76a _ZN2CA11Transaction4pushEv + 312
1   QuartzCore                          0x00007fff95f8c60a _ZN2CA11Transaction15ensure_implicitEv + 276
2   QuartzCore                          0x00007fff95f916f5 _ZN2CA5Layer13thread_flags_EPNS_11TransactionE + 37
3   QuartzCore                          0x00007fff95f91642 _ZN2CA5Layer4markEPNS_11TransactionEjj + 64
4   QuartzCore                          0x00007fff95f931df _ZN2CA5Layer25set_needs_display_in_rectERK6CGRect + 315
5   AppKit                              0x00007fff97e7ebdd _NSBackingLayerSetNeedsDisplayInRect + 319
6   QuartzCore                          0x00007fff95f93081 -[CALayer setNeedsDisplay] + 62
7   AppKit                              0x00007fff97e7ea77 -[NSView(NSInternal) _setLayerNeedsDisplayInViewRect:] + 648
8   AppKit                              0x00007fff98505049 NSViewSetNeedsDisplayInRect + 838
9   AppKit                              0x00007fff97e13eed -[NSView setNeedsDisplay:] + 81
10  AppKit                              0x00007fff97e2ddc0 -[_NSThemeWidget update] + 166
11  AppKit                              0x00007fff980aa844 -[NSThemeFrame _updateButtonState] + 41
12  AppKit                              0x00007fff98101fff -[NSWindow(NSSheets) _detachSheetWindow:] + 641
13  AppKit                              0x00007fff98101a1a -[NSMoveHelper(NSSheets) _closeSheet:andMoveParent:] + 546
14  AppKit                              0x00007fff9810178c -[NSWindow(NSSheets) _orderOutRelativeToWindow:] + 105
15  AppKit                              0x00007fff97f232d7 -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 2833

不幸的是,代码库非常大,并且没有从我的代码库中看到源点,我不确定如何追踪它。

有什么建议吗?

【问题讨论】:

    标签: macos cocoa appkit quartz-core


    【解决方案1】:

    我终于找到了一种方法,使用conditional breakpoints + symbolic breakpoints。

    我会设置一个条件 ![[NSThread currentThread] isMainThread]

    编辑:似乎不同版本的 Xcode 对条件的处理方式不同。如果![[NSThread currentThread] isMainThread] 不起作用(您收到一个找不到符号的错误),请尝试![(NSThread*)[NSThread currentThread] isMainThread]。

    并将符号断点设置为回溯中显示的方法之一。根据我之前发布的回溯,符号断点可能是'-[NSView setNeedsDisplay:]'。

    然后,一旦在非主线程上调用了“[NSView setNeedsDisplay:]”,我的断点就会被触发,我可以看到每个线程的状态,包括对调用者的回溯。这让我能够解决问题。

    另外,请注意这个符号断点会极大地减慢调试速度。我不建议让它一直运行。

    【讨论】:

    • 这很棒。但是, ![[NSThread thread] isMainThread] 在我的系统上生成错误。这是条件的确切文本吗?
    • 我现在正在尝试使用 ![NSThread isMainThread] 并收到错误 - 由于评估断点 1.1 条件的错误而停止:“[NSThread isMainThread] == false”无法解析条件表达式:错误:没有已知方法'+isMainThread';将消息发送到方法的返回类型 error: 1 errors parsing expression
    • 试试![(NSThread*)[NSThread currentThread] isMainThread]作为你的条件。
    • 太棒了!这解决了如何调试它。非常有用。我希望我能给你一个以上的支持。谢谢!
    • 没问题!很高兴这对其他人有所帮助,因为我花了很长时间才弄清楚CATransaction 问题。
    【解决方案2】:

    Kyle 的回答很完美,但是我的 Xcode 版本 (6.2) 仍然在抱怨 ![(NSThread*)[NSThread currentThread] isMainThread] 的情况。

    遵循此 Apple 邮件列表消息中的建议: http://prod.lists.apple.com/archives/xcode-users/2015/Nov/msg00073.html

    我使用了这个条件,它对我来说是正确的: ((BOOL)[(NSThread*)[NSThread currentThread] isMainThread]) == NO

    (我没有足够的声誉来发表评论,所以我发布了这个新答案)

    【讨论】:

    • SO 可能会这么傻 :) 这对我来说也适用于 6.2
    • 所需的语法不断变化会让人很烦!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-02
    • 2013-10-28
    • 1970-01-01
    • 2012-08-11
    • 2020-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多