我们的Mac cocos2d应用程序(http://deepworldgame.com)已经随机抛出“TSMProcessRawKeyCode失败”异常一段时间了,我想知道是否有人遇到过此错误或知道如何防止它。
它总是通过ccKeysDown或ccKeysUp中的[NSEvent charactersIgnoringModifiers]调用发生(对于没有修饰符的[NSEvent字符]也会发生这种情况)。我不认为它与特定键有关。有时它只发生一次,然后应用程序继续运行(如果异常被捕获),但有时它基本上无限期地锁定键盘输入并继续导致所有未来按键异常(同样,当捕获这些异常时)。
遗憾的是,我在这个问题上找不到互联网。我找到的一个地方是Adium源代码(https://bitbucket.org/adium/adium/src/6d1f9b903525/Source/AIExceptionController.m),它通过注释捕获了这个异常:
//Ignore various known harmless or unavoidable exceptions (From the system or system hacks)
...
// [TSMProcessRawKeyCode] May be raised by -[NSEvent charactersIgnoringModifiers]
投掷一次确实无害,但是当它发生连续发射时,这是一个真正的问题 - 尤其是当你处于全屏模式并且无法使用cmd-F逃生时!
所以,如果有人有任何想法或经验,我将非常感激。这几乎就是我们应用中剩下的超级细菌,我很想把它压成灰尘。
谢谢!
这是典型的堆栈跟踪(MacManager.m是我们的对象,它实现了cocos2d键盘委托协议):
Crashed Thread: 7 CVDisplayLink
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Application Specific Information:
objc[28871]: garbage collection is OFF
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'TSMProcessRawKeyCode failed (-192)'
*** Call stack at first throw:
(
0 CoreFoundation 0x95b27d87 __raiseError + 231
1 libobjc.A.dylib 0x9315a149 objc_exception_throw + 155
2 CoreFoundation 0x95a8f619 +[NSException raise:format:arguments:] + 137
3 CoreFoundation 0x95a8f589 +[NSException raise:format:] + 57
4 AppKit 0x9ac01c1f _convertEventRefToString + 300
5 AppKit 0x9ab23b5e -[NSEvent charactersIgnoringModifiers] + 880
6 Deepworld 0x0001fd8a -[MacManager ccKeyDown:] + 65
7 CoreFoundation 0x95a7d091 -[NSObject performSelector:withObject:] + 65
8 Deepworld 0x0006bc95 -[CCEventDispatcher keyDown:] + 80
9 CoreFoundation 0x95a7d091 -[NSObject performSelector:withObject:] + 65
10 Deepworld 0x0006c014 -[CCEventDispatcher dispatchQueuedEvents] + 143
11 Deepworld 0x0006a9a4 -[CCDirectorDisplayLink getFrameForTime:] + 155
12 Deepworld 0x0006aaf1 MyDisplayLinkCallback + 40
13 CoreVideo 0x9b44a5e1 _ZN13CVDisplayLink9performIOEP11CVTimeStamp + 489
14 CoreVideo 0x9b4494e4 _ZN13CVDisplayLink11runIOThreadEv + 876
15 CoreVideo 0x9b449161 _ZL13startIOThreadPv + 160
16 libsystem_c.dylib 0x968a4ed9 _pthread_start + 335
17 libsystem_c.dylib 0x968a86de thread_start + 34
)
答案 0 :(得分:2)
我认为发送事件通常不是线程安全的,更不用说在+ [NSThread detachNewThreadSelector:toTarget:withObject:]中创建的线程(使用Objective-C运行创建的线程 - 时间在回溯中有__NSThread__main__。)
我猜您的应用程序是Deepworld二进制部分 - 在调度事件时,请尝试使用 - [NSObject performSelectorOnMainThread:waitUntilDone:],而不是在主线程上调度事件。