JUCE
JUCE copied to clipboard
[Bug]: OpenGL setNativeSharedContext with attach() randomly not working
Detailed steps on how to reproduce the bug
Hello, On the latest Juce 8 dev branch as of writing this, I’m facing an issue with sharing OpenGL contexts, tried to go deep in debug but didn’t find anything relevant…
I created a minimal program for the sake of the issue. I have 2 components :
Component A (the main window with the titlebar) :
has OpenGLContext A and a FrameBuffer draws a triangle into the framebuffer draws the framebuffer twice in the window, bottom left and top right (so far so good) Component B (the small square window on the top left)
has OpenGLContext B that has setNativeSharedContext(ContextA) draw context A’s framebuffer twice, bottom left and top right When I launch the program, I have 90% chance of seeing the following picture, showing white rectangles instead of the framebuffer’s texture
To test faster, I added a keypress shortcut to do :
detach(); attach(*this); on the second window. I then hit the shortcut and will see that sometimes, (I’d say around 20%, but actually really random) the texture will be actually showing like the picture above. And most often going back to white rectangle.
I tried breaking and inspecting potential differences and changing variables inside the attach() function when it works and doesn’t work, but couldn’t find anything that was clearly different in the 2 scenarios. Doesn’t mean there aren’t, just that they’re not trivial.
I have a suspicion that the randomness of this problem is due to timing and context availability.
Interesting this to note, I tried putting CriticalSection locks around both the renderGL in the mainwindow and the attach function in the second window, and this way I never get a good texture, it will always stay white.
Any help appreciated, I’ve spent a good amount of time on this already and feel a bit lost on what I can do next :slight_smile:
I can provide the source and executable of this example if anyone wants to test, this has only been tested on Win11 x64 for now.
Thank you
What is the expected behaviour?
I would really be happy with this function always working :)
Operating systems
Windows
What versions of the operating systems?
11
Architectures
64-bit
Stacktrace
No response
Plug-in formats (if applicable)
No response
Plug-in host applications (DAWs) (if applicable)
No response
Testing on the develop
branch
The bug is present on the develop
branch
Code of Conduct
- [X] I agree to follow the Code of Conduct