[BUG] JUCE >=6.0.1 - Focus problem with OpenGLContext

[EDIT] More accurate data on the 4th post below.

I’m sorry if I cannot describe well my problem, but here is it:
I’ve just updated my app from juce6 to master (juce 6.0.7), and on Linux 64 bits, after launching the app, opening the Popup menu at the top (File/Edit/etc.) opens it for a very brief moment, then it disappears. The top bar buttons (maximize/minimize/close) are also unresponsive. Please note that I use my own custom Look’n’Feel.

If I click on another application, then focus back to my app, everything works fine, the menus are ok and the top bar are responsive.
The problem does NOT appear on Windows (I didn’t test on Mac). It was working perfectly fine with JUCE6.0.0. Whether I launch the app via CLion or via command line gives the same result.

It seems to be a focus problem. But I didn’t change anything in the code from JUCE6.0.0 to 6.0.7…

Has anyone an idea on how to correct this? Thanks!

If you didn’t change anything in your own code between using JUCE 6.0.0 and 6.0.7, then the issue most likely comes from JUCE itself.

If you use JUCE from a Git repository, you can use git bisect to find the exact commit where the behavior changed. However, git bisect requires a bit of practice, so it might be challenging.

Another approach is to make the smallest example possible. Try to remove everything that is not necessary to demonstrate the issue. And while doing that, you might identify a part which has an impact on the behavior (i.e. with it, there is an issue, without it, there is none). Once you have the smallest example, you can again compare between JUCE 6.0.0 and 6.0.7 to confirm that the issue comes from JUCE itself.

I hope this helps!

1 Like

Ah, it seems the culprit is:

I do this on the main DocumentWindow. Always did, never had any problem. I wouldn’t want to remove it, it provides a substantial smoothness in how the UI is drawn.

Ok, after more tests, I found out that the bug has started from JUCE 6.0.1 (still present in JUCE 6.0.7 - does NOT happen in 6.0.0 and before).

To reproduce it, very simple. Create a simple GUI app, and attach an OpenGLContext to the MainWindow:

class MainWindow    : public juce::DocumentWindow
        explicit MainWindow (juce::String name)
            : DocumentWindow ( /* ... */),
              openGLContext()         // ********** ADDED LINE
            setUsingNativeTitleBar (false);
            setContentOwned (new MainComponent(), true);

            openGLContext.attachTo(*this);     // ********** ADDED LINE

           // ...
           // ...
        juce::OpenGLContext openGLContext;    // ********** ADDED LINE

As stated in the previous post, the app is no more focused when it is launched. The user has to select another application, then select the app again.
Another consequence is that toolbar menus only appear for a split second, then disappear.

This happens on Linux (tested on Debian 64 bits), not on Windows (didn’t test on Mac).

Does this still happen if you attach the OpenGLContext to the top-level component instead of the MainWindow itself? Are you testing this with a completely blank Projucer project (other than the GL context)? I was unable to reproduce it on Ubuntu or Debian, the window is correctly focused on app startup and menus are appearing correctly.

I tested with Ubuntu 18 and Debian 10 (both 64 bits), the problem appears for both.

Here is the project I used. It is the simplest GUI project:

(JUCE must be put at the same level as the project, but you can see that in the CMakeLists file).

Does this still happen if you attach the OpenGLContext to the top-level component instead of the MainWindow itself?

I’m afraid I don’t understand, the MainWindow is already the top-level component. If I use the getTopLevelComponent() method, it returns the same object as MainWindow.