NSStatusItem “kCG…” Errors

你说的曾经没有我的故事 提交于 2021-01-28 12:03:14

问题


For some reason, in the Console I'm getting

: kCGErrorIllegalArgument: CGSUnregisterWindowWithSystemStatusBar: Invalid window

: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.

with (I think) this code ...

- (void)applicationDidResignActive:(NSNotification*)aNotification
{
        statusItem = [[NSStatusBar systemStatusBar] 
                       statusItemWithLength:NSVariableStatusItemLength];
        [statusItem setHighlightMode:YES];
        [statusItem setEnabled:YES];

            //Set menubar item's tooltip
        [statusItem setToolTip:@"Nucleus"];
        [statusItem setMenu:theMenu];
            //Set the menubar item's title
        [statusItem setTitle:[NSString stringWithString:@"N"]];

    [statusItem retain];

}

- (void)applicationDidBecomeActive:(NSNotification*)aNotification
{
    [[NSStatusBar systemStatusBar] removeStatusItem:statusItem];
}

I believe this is the stack trace (?) :

0x00007fff8667349b <+0000> push %rbp
0x00007fff8667349c <+0001> mov %rsp,%rbp
0x00007fff8667349f <+0004> mov %edi,%eax
0x00007fff866734a1 <+0006> leaveq
0x00007fff866734a2 <+0007> retq
0x00007fff866734a3 <+0008> nop

Why? How can I fix this?

I'm using Cocoa on Mac?


回答1:


I'm not sure what's causing the error, but I do notice that you're leaking statusItem every time the application deactivates. Perhaps adding a [statusItem release] after removing it from the statusBar will help (it will definitely fix your leak).



来源:https://stackoverflow.com/questions/5478826/nsstatusitem-kcg-errors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!