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

Support multiple event loop instances on Windows #3141

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Zoxc
Copy link

@Zoxc Zoxc commented Oct 13, 2023

This allows multiple event loop instances on Windows.

This is blocked on #3061 as currently using event loops of different types can cause unsafety.

@kchibisov
Copy link
Member

I'm not sure this is really a good idea. Mostly because objects created by different loops can't really interact with each other. Maybe that's not true on Windows, but I'm not sure we should allow such a use case...

@Zoxc
Copy link
Author

Zoxc commented Oct 15, 2023

Not being able to create multiple windows is a rather major limitation that makes winit not suitable for use in other libraries. If that's out of scope, that should be clearly stated in the readme so libraries can use other alternatives.

Currently It can create windows and Winit is designed to be a low-level brick in a hierarchy of libraries very much imply the ability to create multiple windows.

@kchibisov
Copy link
Member

Not being able to create multiple windows is a rather major limitation that makes winit not suitable for use in other libraries. If that's out of scope, that should be clearly stated in the readme so libraries can use other alternatives.

You can create as many windows as you want with the one event loop. I don't understand why you need multiple loops

@kchibisov
Copy link
Member

@Zoxc
Copy link
Author

Zoxc commented Oct 15, 2023

Libraries based on winit all end up creating their own event loops, which makes them not composable. You're unable to actually create multiple windows using libraries built on winit.

@kchibisov
Copy link
Member

kchibisov commented Oct 15, 2023

@Zoxc well, good for them. But you can't have multiple event loops on macOS for example, you also can't mix winit objects from multiple event loops, since it'll terminate the other loop if you do that.

You need a separate processes for them. What you want can only work on basically Windows, and that's about it.

@Zoxc
Copy link
Author

Zoxc commented Oct 15, 2023

Well this enables it for Windows only. It also works on X11 / Wayland.

@kchibisov
Copy link
Member

It also works on X11 / Wayland.

No, Wayland doesn't work like that, it'll need a special API for multiple event loop on Wayland, since it relies on sub-queues. It doesn't work on X11 as well nice, because error handling is per_process so error in one loop can kill other loop.

As I said, no-one doing something like that usually, they just give a handle to library to draw into (see egui), none GUI clients want to do stuff like that, it's wrong.

We could have an option to create as many loops as you want, but why a portable toolkit could enforce a non-portable design? We have exception on wasm, but we have a separate call and wasm just works so much different than anything else that it's fine.

@Zoxc
Copy link
Author

Zoxc commented Oct 15, 2023

I don't think your arguments about X11 / Wayland hold water. They also do not apply to exposing this on Windows.

@kchibisov
Copy link
Member

I don't think your arguments about X11 / Wayland hold water. They also do not apply to exposing this on Windows.

I'm saying that multiple event loops need a different API to even try to make it work in a safe, reasonable way. Just slapping API which obviously can't work is not the way forward, not that folks usually do it that way, because libraries system libraries have global shared state, which you should be careful about. I'm still not sure why should we try to continue with such designs, just create processes if you really need multiple event loops, that's how usually it's done by clients demanding such API.

Out of all platforms only Wayland with subqueues was designed with the concurrent multi-threaded access to the windows, yet it'll need some sort of Coloring in winit to make it work, since Window created by one event loop can't work with another one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants