我正在处理一个可可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 raised2010-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编译时不会发生此错误。

谢谢你的帮助!

弗洛里安

最佳答案

我正在使用POSIX线程本地存储。尽管我的应用程序当前是单线程的,但是使我的TLS变量成为常规变量,线程全局变量可以缓解崩溃。每个变量只能有一个TLS实例。

关于为何POSIX TLS不适用于Cocoa的任何评论。这是一个已知的问题?

关于multithreading - 无法解释的NSUndoManager崩溃/ cocoa 应用中的断言,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3645770/

10-10 09:46