Menus take 600 ms to open

Hi all,

In our app, popup menus take around 600 ms to appear on Windows when an OpenGLContext is continuously repainting. I’ve created a minimal example to demonstrate the bug:

struct MainComponent : Component
{
    MainComponent()
    {
        addAndMakeVisible(button);
        button.setBounds(20, 20, 160, 30);
        button.onClick = []
            {
                struct Content : Component
                {
                    Content()
                    {
                        addAndMakeVisible(button);
                        button.setBounds(20, 20, 160, 30);
                        button.onClick = [this]
                            {
                                PopupMenu menu;
                                menu.addItem(1, "Item 1");
                                menu.addItem(2, "Item 2");
                                menu.addItem(3, "Item 3");
                                menu.showMenuAsync({});
                            };

                        setSize(200, 70);
                    }

                    TextButton button{ "Show menu" };
                };

                DialogWindow::LaunchOptions options;
                options.content.setOwned(new Content());
                options.launchAsync();
            };

        context.setPreferredVersion({ 3, 2 });
        context.setPreferredProfile(OpenGLProfile::core);
        context.setContinuousRepainting(true);
        context.attachTo(*this);

        setSize(400, 400);
    }

    OpenGLContext context;
    TextButton button{ "Open dialog" };
};

The menu in the example is opened from a dialog window, because that was the only way I could reproduce the issue in a minimal example. In our own app, we also see it in other places.

Turning off continuous repainting and calling triggerRepaint() from a VBlankAttachment fixes the issue for our app. If that’s the right fix, we’ll go with it, but if this is a JUCE bug, I hope it can be fixed.

This issue has been around for a while and is still present with JUCE 9.0.4.

Best,

Jelle

1 Like

I think it happens with native rendering too, it’s just how the menus are implemented.

It can make the menus feel slugging so a JUCE fix would be nice.

600 ms is a surprisingly long time.

If the message queue was stalled for that long the rest of your app would be in real trouble, and if we were waiting for a GPU frame I’d expect to wait at most 3 frames.

There are some D2D functions that take a while, but I’m struggling to reproduce anything like what you are experiencing. Could you let us know what machine you are running on?

Can you try the develop branch?

I can reproduce the issue now.

1 Like

@t0m any update on this bug?

A proper fix for this issue is quite complex. It’s still at least another couple of weeks away from being ready.

1 Like