Unexplainable NSUndoManager crash / assert in Cocoa app
I'm having a weird issue, with a Cocoa, OpenGL application I am working on. Whenever I launch my application I am getting the following messages / assertion failure on the console, related to eh NSUndoManager. I am not using the undo manager, by the way.
2010-09-05 03:28:49.184 CocoaCoreTest[51721:a0f] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /SourceCache/Foundation/Foundation-751.29/Misc.subproj/N开发者_开发技巧SUndoManager.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'
I am running my GUI on the main thread and I'm not spawning any other threads, in fact. I get this crash in Debug and Release mode, when I compile for x86_64. However, interestingly, this error does not occur when I compile for i386.
Thanks for your help!
Florian
I am using POSIX thread local storage. Making my TLS variables regular, thread global variables alleviates the crash, although my app is currently single threaded, ie. there should only be one TLS instance per variable.
Any comments on why POSIX TLS might not work with Cocoa. Is this a known issue?
精彩评论