Mouse click detecting bug in PopupMenu

Hi,

We’ve been noticing that often immediately after showing a PopupMenu, the menu detects a mouse click on the menu causing the menu to close immediately after showing, and firing the item click callback. While trying to reproduce it in an example project, I noticed that the bug happens only when the app’s main thread is really busy. I created a small example project with a timer and some Thread::sleep calls to simulate the app being busy. This is now reproducable, see the code below.

In our real app we do not have a main thread being so busy but we do have an OpenGL thread running which might cause problems related to this. In our app this bug happens approximately once every four times.

The bug happens on Windows on JUCE 8.0.2, JUCE 7.0.12 and current develop.

struct MainComponent  : juce::Component, juce::Timer
{
    MainComponent() 
    {
        setSize(600, 400);

        startTimerHz(10); // simulate busy app
    }

    void paint(juce::Graphics& g) override
    {
        g.fillAll(juce::Colours::black);
    }

    void mouseDown(const juce::MouseEvent& e) override
    {
        juce::PopupMenu menu;
            
        menu.addItem("Item", [&]
            {
                juce::NativeMessageBox::showAsync(juce::MessageBoxOptions().withTitle("Item Clicked!"), nullptr);
            });

        menu.showMenuAsync({});
    }

    void timerCallback() override
    {
        juce::Thread::sleep(100);
    }
};

Best,
Jelle

Is this issue seen by the JUCE team?

Yes, I’m investigating.

1 Like

Thanks for reporting. We’ve pushed a fix here:

Please try it out and let us know if you notice any new problems.

1 Like

@reuk

Unfortunately, we’re still encountering issues. Occasionally, the mouse detection algorithm mistakenly detects mouse jumps. This problem occurs specifically when there are many submenus.

The popup menu can enter an infinite loop, continuously detecting mouse jumps. I’ve updated my example code locally to include many submenus, and the glitch is demonstrated in the video below:

The above demonstration does not represent the issues in our actual application. For our actual application, when using a context menu: some mouse clicks are ignored, some mouse clicks are mistakenly detected, the highlighted item may flicker, and the context menu as a whole is slow and unreliable. Many of these issues have only appeared since the recent fix. The issue was originally only mouse clicks being mistakenly detected.

Perhaps the issue demonstrated above is not relevant to the issues affecting our actual application.

@reuk
Any updates?

It’s on the backlog, but we’ve been busy with the Audio Developer Conference recently, so it might be a little while before we get to investigate this issue.

I also see issues with the recent changes:

Yes, we’re tracking that issue too.

1 Like

We just updated to the latest JUCE. The issue seems to be resolved.