【问题标题】:Unexplainable NSUndoManager crash / assert in Cocoa appCocoa 应用程序中无法解释的 NSUndoManager 崩溃/断言
【发布时间】:2010-09-05 10:40:18
【问题描述】:

我遇到了一个奇怪的问题,我正在开发一个 Cocoa、OpenGL 应用程序。每当我启动我的应用程序时,我都会在控制台上收到以下与 eh NSUndoManager 相关的消息/断言失败。顺便说一句,我没有使用撤消管理器。

2010-09-05 03:28:49.184 CocoaCoreTest[51721:a0f] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /SourceCache/Foundation/Foundation-751.29/Misc.subproj/NSUndoManager.m:271
2010-09-05 03:28:49.188 CocoaCoreTest[51721:a0f] +[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.
2010-09-05 03:28:49.189 CocoaCoreTest[51721:a0f] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /SourceCache/Foundation/Foundation-751.29/Misc.subproj/NSUndoManager.m:271
2010-09-05 03:28:49.190 CocoaCoreTest[51721:a0f] An uncaught exception was raised 2010-09-05 03:28:49.190 CocoaCoreTest[51721:a0f] +[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.
2010-09-05 03:28:49.192 CocoaCoreTest[51721:a0f] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.'
*** Call stack at first throw: ( 0 CoreFoundation 0x00007fff83e97cc4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff883bb0f3 objc_exception_throw + 45
2 CoreFoundation 0x00007fff83e97ae7 +[NSException raise:format:arguments:] + 103
3 Foundation 0x00007fff84cf2d5a -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198
4 Foundation 0x00007fff84c4b936 +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 140
5 AppKit 0x00007fff823219f9 -[NSApplication run] + 689
6 AppKit 0x00007fff8231a5f8 NSApplicationMain + 364
7 CocoaCoreTest 0x000000010003b753 main + 33
8 CocoaCoreTest 0x0000000100021608 start + 52
9 ??? 0x0000000000000001 0x0 + 1
) terminate called after throwing an instance of 'NSException'

事实上,我在主线程上运行我的 GUI,并没有产生任何其他线程。当我为 x86_64 编译时,我在调试和发布模式下遇到了这个崩溃。然而,有趣的是,当我为 i386 编译时,并没有出现这个错误。

感谢您的帮助!

弗洛里安

【问题讨论】:

    标签: multithreading cocoa crash assert nsundomanager


    【解决方案1】:

    我正在使用 POSIX 线程本地存储。使我的 TLS 变量定期,线程全局变量减轻了崩溃,尽管我的应用程序当前是单线程的,即。每个变量应该只有一个 TLS 实例。

    关于为什么 POSIX TLS 可能不适用于 Cocoa 的任何 cmets。这是一个已知问题吗?

    【讨论】:

    • 回答我自己的问题:我很粗心,遇到了静态初始化顺序问题。我的 TLS 变量是一个静态初始化的成员变量,并且在访问该变量时尚未调用构造函数。我更改了我的类以从静态方法返回静态变量,以避免这些初始化顺序问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-03
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多