Skip to content
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

Restrict display creation unless it's destroyed #1628

Open
baehny opened this issue Sep 3, 2023 · 3 comments
Open

Restrict display creation unless it's destroyed #1628

baehny opened this issue Sep 3, 2023 · 3 comments

Comments

@baehny
Copy link
Contributor

baehny commented Sep 3, 2023

Creating a new display with Display::new(...) using WGL, changes the current OpenGL context, or to be more precise unsets the current context. This is caused by the construction and destruction of a temporary context in glutin::wgl::load_extra_functions.

Call of load_extra_functions in Display::new

wglMakeCurrent(..) in load_extra_functions(...)

I'm not sure if there is a good way to restore the original context, but I think this behaviour should atleast be described in the documentation of glutin::wgl::load_extra_functions and Display::new.

I hope I have some spare time to provide a suggestion in the next days.

@kchibisov kchibisov added the WGL label Sep 3, 2023
@kchibisov
Copy link
Member

I think the issue is that we even try to do more than one display, because the intention was that you don't do that, but we never added some protection against that.

It's true that we can restore things btw, but what's your use case with multiple displays?

@baehny
Copy link
Contributor Author

baehny commented Sep 3, 2023

Yes, I created multiple windows and called Display::new for every window. I could probably refactore my code to create a single instance of Display. However, finding the issue took me some time so maybe there is a solution that prevents that kind of problem in the first place.

@kchibisov
Copy link
Member

@baehny the Display is accessible from literally any object, like config, surface, etc, so you can create a config and just pass it around getting the display from it.

Yeah, we could probably restore the current context, but it's implicit and could result in un desired behavior.

Glutin should basically disallow creating multiple displays referring to the same native display more than once, since it's how it should work. Display is usually a singleton under the hood (based on native display). It just on windows we must create context + window to get the OpenGL icd loader working, so we can setup context later correctly.

@kchibisov kchibisov changed the title WGL Current context is no longer current after calling Display::new(...) Restrict display creation unless it's destroyed Nov 12, 2024
@kchibisov kchibisov added the api label Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants