Open ItsVeeBot opened 1 week ago
You can only draw or interact with pyglet objects from within the same context they were created in. See this example: https://github.com/pyglet/pyglet/blob/master/examples/window/multiple_windows.py
This also applies to events that get dispatched when another context is current.
@ItsVeeBot what this means is that your code should manage the active OpenGL context that your process holds to when it is drawing or preparing elements for drawing through pyglet API. This abstract imperative translates to employing calls to Window.switch_to()
such that your active OpenGL context is that of the window that you are drawing or preparing elements for drawing for.
Because there is only one OpenGL context active at any time ― you can wake up in a callback from one window, with your active OpenGL context being that of another window of your application.
Window.switch_to()
switches the OpenGL context to that of the Window
object that it is called on, which is how you switch to an OpenGL context to match the window that you want to draw for.
There have been some suggestions to alleviate this onus away from user code, but currently this is what you have to accomplish to avoid this exact type of crash ― analyze your flows to figure where you need to tell pyglet that the OpenGL context might need to be switched to the window that you mean to draw to ― there's always one active OpenGL context and pyglet does not guess which window's OpenGL context it should be unless you tell it.
I hope this is somewhat of a fair summary, as I'd like to cement my understanding of it before cleaning up my own multi-window application to be as minimal as possible yet sufficiently safe in setting the OpenGL context.
Maybe some API for identifying the OpenGL context (?!) could be one way for developers to scaffold this safety around their code flows rather than relying purely on theoretical analyses of their application code.
Describe the bug When opening multiple windows and attempting to draw text to one of them, Pyglet throws a pyglet.gl.lib.GLException:
System Information:
How To Reproduce