Possible bug: SystemTrayIconComponent cannot be removed at runtime


#1

It seems the SystemTrayIconComponent is not freeing some resources correctly and the icon will still be shown in the menu area, even after the SystemTrayIconComponent has been freed.

To reproduce, use the JUCE Demo and instead of closing the app just free the tray icon:

void MainAppWindow::closeButtonPressed()
{
    //JUCEApplication::getInstance()->systemRequestedQuit();
    taskbarIcon = nullptr;
}

The icon will still be shown, clicking on it will crash the app.


#2

I tried your change, but when I clicked the button, the icon disappears immediately, nothing crashes, and everything works as expected (?)


#3

Sorry, please try the following with the Demo app from the current tip:

void MainAppWindow::closeButtonPressed()
{
    if(taskbarIcon)
        taskbarIcon = nullptr;
    else
        taskbarIcon = new DemoTaskbarComponent();

    //JUCEApplication::getInstance()->systemRequestedQuit();
}

Then click the app close button a few times.

For me it crashes in frameChanged of juce_mac_SystemTrayIcon.cpp

The Xcode console output shows:

2014-06-30 07:39:27.247 JuceDemo[520:303] -[__NSBlockVariable__ view]: unrecognized selector sent to instance 0x60000004f660
2014-06-30 07:39:27.251 JuceDemo[520:303] -[__NSBlockVariable__ view]: unrecognized selector sent to instance 0x60000004f660
2014-06-30 07:39:27.271 JuceDemo[520:303] (
    0   CoreFoundation                      0x00007fff9139825c __exceptionPreprocess + 172
    1   libobjc.A.dylib                     0x00007fff98984e75 objc_exception_throw + 43
    2   CoreFoundation                      0x00007fff9139b12d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00007fff912f6322 ___forwarding___ + 1010
    4   CoreFoundation                      0x00007fff912f5ea8 _CF_forwarding_prep_0 + 120
    5   JuceDemo                            0x00000001005fa169 _ZN4juce23SystemTrayIconComponent5Pimpl19SystemTrayViewClass12frameChangedEP11objc_objectP13objc_selectorP14NSNotification + 73
    6   CoreFoundation                      0x00007fff91366e0c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
    7   CoreFoundation                      0x00007fff9125a8dd _CFXNotificationPost + 2893
    8   Foundation                          0x00007fff9afc97ba -[NSNotificationCenter postNotificationName:object:userInfo:] + 68
    9   AppKit                              0x00007fff93c49aa8 -[NSWindow _setFrameAfterMove:] + 411
    10  AppKit                              0x00007fff93c1f0d0 -[NSWindow _windowMovedToRect:] + 627
    11  AppKit                              0x00007fff93c498f7 -[NSWindow _windowMoved:] + 159
    12  AppKit                              0x00007fff93b9bcc1 -[NSWindow sendEvent:] + 3721
    13  AppKit                              0x00007fff93c9911b -[NSStatusBarWindow sendEvent:] + 247
    14  AppKit                              0x00007fff93b3c71b -[NSApplication sendEvent:] + 2348
    15  AppKit                              0x00007fff9398ca19 -[NSApplication run] + 646
    16  JuceDemo                            0x000000010034d6f7 _ZN4juce14MessageManager15runDispatchLoopEv + 119
    17  JuceDemo                            0x000000010034d600 _ZN4juce19JUCEApplicationBase4mainEv + 352
    18  JuceDemo                            0x000000010034d43c _ZN4juce19JUCEApplicationBase4mainEiPPKc + 60
    19  JuceDemo                            0x0000000100001853 main + 51
    20  libdyld.dylib                       0x00007fff9728e5fd start + 1
    21  ???                                 0x0000000000000003 0x0 + 3
)

 


#4

Ah! Thanks, that should be sorted out now.


#5

Works perfect now, thanks!