Multiple windows with GL contexts

From other threads here, I’ve come to understand that you shouldn’t use multiple GL contexts attached to multiple documentwindows (all in the same process, of course).

Depending on who you ask this will either give you a black screen, or massive performance drop.

Is this correct? The threads I’m viewing are rather old, so this may have changed.

And if so … can we really recommend openGL in plugins? I mean, even if very few DAWs use openGL, surely you could have multiple plugins using openGL, or multiple instances of the same plugin for that matter. Won’t you get this same issue?

Actually, testing here is seems that multiple windows all running with openGL contexts attached is fine.

What is not fine is a documentwindow with an attached GLContext and with a content component that also has an attached context (see screenshot).

That seems like a different issue though. More like a context inside a context, which is understandably probably not a best practice.

Anyway, would welcome any thoughts or guidance.

I recently tried to use multiple windows with openGL contexts on Linux and failed in doing so: Every time the windows overlapped, the entire GUI freezed. However, this was on Linux, where openGL with NVidia Gtx cards behaves very strangely anyways (laggy with vsync, 10k FPS without). So this might not be representative. I’m not sure that my way to set up openGL is the right way to do either, since there was very little information when I started out.

Anyways, I’ll follow this thread for more information :+1:

I currently cannot run more than 4 instances of my plugin on windows. Although the size of the component changes that number.

I’m currently seeking a solution to this as well.

Should we just be using a static context shared among multiple renders, then attach them to individual components?

Are you using the most recent version of JUCE from the develop branch? The OpenGLContext has been overhauled significantly in JUCE 7, so it’s definitely worth making sure you’re up-to-date.

What happens with more than four instances? Do you get a crash, or deadlock, or slow down, or incorrect rendering, or something else?

Have you tested on multiple Windows machines, with different graphics cards? If so, do you see the same behaviour on all systems?

Yes, I can not get a debug error in the debugger. It starts with some sort of lock, then freezes. I can get it to crash on the 7th or 10th by commenting out classes. Then with no clear issue in my code it will hang and fail to create the vst3 windows in FL Studio, Ableton 10, Ableton 11, all tested on windows 10 and 11. (4 different computers)

I’ve tried removing opengl and the crash still happens, and I’m not using anything static. I tried going back to 6.1.6 aswell and got a similar crash. I’ve also tried 7.03, 7.05, and the most recent development branch.

Is it possible to run out of ram? Could it be that I am dynamic casting my child UI component to the processor and then moving it back with a dynamic cast on construction, that it is somehow messing up the image cache or ownership of a window? I’ve also tried just creating it straight up and it still breaks but only on the 4th… lol

There are hundreds of child components and I for the life of me could not find broken code.

I have component painting enabled. So idk if that is still an issue. Any clarity you can provide would be greatly apprcieated!

Update: it seems to be a WIN32 API failed call by JUCE on the 4th window… but I don’t know why