2010-09-05 39 views
1

我有一个奇怪的问题,与我正在开发的Cocoa,OpenGL应用程序。每当我启动我的应用程序时,我在控制台上收到以下消息/断言失败,与NSUndoManager相关。顺便说一下,我没有使用撤消管理器。可可的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编译时,这个错误不会发生。

感谢您的帮助!

Florian

回答

1

我正在使用POSIX线程本地存储。虽然我的应用程序目前是单线程的,也就是说,使我的TLS变量保持正常,但线程全局变量缓解了崩溃。每个变量只能有一个TLS实例。

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

+0

回答我自己的问题:我很粗心,并且有一个静态的初始化顺序问题。我的TLS变量是一个静态初始化的成员变量,构造函数在访问该变量时尚未被调用。我改变我的类从静态方法返回静态变量,以避免这些初始化顺序问题。 – FlorianZ 2010-09-06 02:57:36