0

ときどき、主に負荷が高いときに、次のエラーが発生します。

2013-04-23 23:53:13.595 MusicPlayer[74705:6303] unrecognized type is -2
2013-04-23 23:53:14.686 MusicPlayer[74705:6303] *** Assertion failure in -[NSEvent _initWithCGSEvent:eventRef:], /SourceCache/AppKit/AppKit-1187.37/AppKit.subproj/NSEvent.m:1348
2013-04-24 00:40:47.358 MusicPlayer[74705:6303] unrecognized type is -2
2013-04-24 00:40:47.561 MusicPlayer[74705:6303] *** Assertion failure in -[NSEvent _initWithCGSEvent:eventRef:], /SourceCache/AppKit/AppKit-1187.37/AppKit.subproj/NSEvent.m:1348
2013-04-24 00:42:49.016 MusicPlayer[74705:6303] unrecognized type is -2
2013-04-24 00:42:49.017 MusicPlayer[74705:6303] *** Assertion failure in -[NSEvent _initWithCGSEvent:eventRef:], /SourceCache/AppKit/AppKit-1187.37/AppKit.subproj/NSEvent.m:1348
2013-04-24 00:42:53.689 MusicPlayer[74705:6303] unrecognized type is -2
2013-04-24 00:42:53.689 MusicPlayer[74705:6303] *** Assertion failure in -[NSEvent _initWithCGSEvent:eventRef:], /SourceCache/AppKit/AppKit-1187.37/AppKit.subproj/NSEvent.m:1348
2013-04-24 00:43:01.091 MusicPlayer[74705:6303] unrecognized type is -2
2013-04-24 00:43:01.091 MusicPlayer[74705:6303] *** Assertion failure in -[NSEvent _initWithCGSEvent:eventRef:], /SourceCache/AppKit/AppKit-1187.37/AppKit.subproj/NSEvent.m:1348
2013-04-24 00:43:06.840 MusicPlayer[74705:6303] unrecognized type is -2
2013-04-24 00:43:06.840 MusicPlayer[74705:6303] *** Assertion failure in -[NSEvent _initWithCGSEvent:eventRef:], /SourceCache/AppKit/AppKit-1187.37/AppKit.subproj/NSEvent.m:1348
EXCEPTION
Traceback (most recent call last):
  File "/Users/az/Programmierung/music-player/mac/build/Release/MusicPlayer.app/Contents/Resources/Python/mediakeys.py", line 71, in runEventsCapture
    line: Quartz.CFRunLoopRun()
    locals:
      Quartz = <local> <module 'Quartz' from '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/Quartz/__init__.py'>
      Quartz.CFRunLoopRun = <local> <objc.function 'CFRunLoopRun' at 0x1027dfb30>
error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
EXCEPTION
Traceback (most recent call last):
  File "/Users/az/Programmierung/music-player/mac/build/Release/MusicPlayer.app/Contents/Resources/Python/mediakeys.py", line 71, in runEventsCapture
    line: Quartz.CFRunLoopRun()
    locals:
      Quartz = <local> <module 'Quartz' from '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/Quartz/__init__.py'>
      Quartz.CFRunLoopRun = <local> <objc.function 'CFRunLoopRun' at 0x1027dfb30>
error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
EXCEPTION
Traceback (most recent call last):
  File "/Users/az/Programmierung/music-player/mac/build/Release/MusicPlayer.app/Contents/Resources/Python/mediakeys.py", line 71, in runEventsCapture
    line: Quartz.CFRunLoopRun()
    locals:
      Quartz = <local> <module 'Quartz' from '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/Quartz/__init__.py'>
      Quartz.CFRunLoopRun = <local> <objc.function 'CFRunLoopRun' at 0x1027dfb30>
error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
new song: Tiestö - Reepublic, 00:15, mp3, 125 kbit/s, 233 KB
EXCEPTION
Traceback (most recent call last):
  File "/Users/az/Programmierung/music-player/mac/build/Release/MusicPlayer.app/Contents/Resources/Python/mediakeys.py", line 71, in runEventsCapture
    line: Quartz.CFRunLoopRun()
    locals:
      Quartz = <local> <module 'Quartz' from '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/Quartz/__init__.py'>
      Quartz.CFRunLoopRun = <local> <objc.function 'CFRunLoopRun' at 0x1027dfb30>
error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
EXCEPTION
Traceback (most recent call last):
  File "/Users/az/Programmierung/music-player/mac/build/Release/MusicPlayer.app/Contents/Resources/Python/mediakeys.py", line 71, in runEventsCapture
    line: Quartz.CFRunLoopRun()
    locals:
      Quartz = <local> <module 'Quartz' from '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/Quartz/__init__.py'>
      Quartz.CFRunLoopRun = <local> <objc.function 'CFRunLoopRun' at 0x1027dfb30>
error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
EXCEPTION
Traceback (most recent call last):
  File "/Users/az/Programmierung/music-player/mac/build/Release/MusicPlayer.app/Contents/Resources/Python/mediakeys.py", line 71, in runEventsCapture
    line: Quartz.CFRunLoopRun()
    locals:
      Quartz = <local> <module 'Quartz' from '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC/Quartz/__init__.py'>
      Quartz.CFRunLoopRun = <local> <objc.function 'CFRunLoopRun' at 0x1027dfb30>
error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType

関連コード:

    import AppKit, Quartz
    from AppKit import NSSystemDefined
    pool = AppKit.NSAutoreleasePool.alloc().init()

    self.runLoopRef = Quartz.CFRunLoopGetCurrent()

    while True:
        # https://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html
        tap = Quartz.CGEventTapCreate(
            Quartz.kCGSessionEventTap, # Quartz.kCGSessionEventTap or kCGHIDEventTap
            Quartz.kCGHeadInsertEventTap, # Insert wherever, we do not filter
            Quartz.kCGEventTapOptionDefault, #Quartz.kCGEventTapOptionListenOnly,
            Quartz.CGEventMaskBit(NSSystemDefined), # NSSystemDefined for media keys
            self.eventTap,
            None
        )
        assert tap

        # Create a runloop source and add it to the current loop
        runLoopSource = Quartz.CFMachPortCreateRunLoopSource(None, tap, 0)
        Quartz.CFRunLoopAddSource(
            self.runLoopRef,
            runLoopSource,
            Quartz.kCFRunLoopDefaultMode
        )

        # Enable the tap
        Quartz.CGEventTapEnable(tap, True)

        try:
            # and run! This won't return until we exit or are terminated.
            Quartz.CFRunLoopRun()
        except Exception:
            # I got this one here once:
            # error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
            sys.excepthook(*sys.exc_info())
            continue # rerun

        # this is a regular quit
        break

    del pool

例外はほとんどの場合、GUI スレッドのハングに伴います (これが、非常に注目に値する可能性があるため、単に無視したくない主な理由です)。

4

1 に答える 1

1

hereから、次のような役立つ情報を入手しました。

実際には、イベント タイプ CGEventType は CGEventType.h で符号なし 32 ビット整数として定義されています。したがって、-2 は実際には 0xFFFFFFFE です。kCGEventTapDisabledByTimeout として定義されている CGEventType.h 内。これについて、次のようなコメントがあります。

  /* Out of band event types. These are delivered to the event tap callback
     to notify it of unusual conditions that disable the event tap. */
  kCGEventTapDisabledByTimeout = 0xFFFFFFFE,
  kCGEventTapDisabledByUserInput = 0xFFFFFFFF

イベントタップがタイムアウトしているようです。そのため、この後、イベントが発生しなくなります。

Python では、イベント タップで、次のようにこのケースを確認できます。

def eventTap(self, proxy, type_, event, refcon):
    if type_ < 0 or type_ > 0x7fffffff:
        # handle it ...

このようなイベント タイプを取得すると、イベント タップが無効になることに注意してください。そのため、イベント ループを再開することをお勧めします。

于 2013-04-24T11:55:51.610 に答える