New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pyglet.gl.lib.GLException when trying to draw text while multiple windows are open #1102
Comments
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 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.
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. |
|
As a side effect of deleneating it in the above I think I have a clearer picture of how to think about my code such that I know exactly where I should I'll try to contribute a less minimal example of how to manage the context in the future (that example doesn't really represent any multi-window application design in any way). |
Thanks a lot for suggesting |
(It's probably time to remove the 'bug' label). |
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
The text was updated successfully, but these errors were encountered: