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

WindowHandle is not sound #3317

Open
daxpedda opened this issue Dec 25, 2023 · 7 comments
Open

WindowHandle is not sound #3317

daxpedda opened this issue Dec 25, 2023 · 7 comments
Labels
B - bug Dang, that shouldn't have happened C - needs discussion Direction must be ironed out S - api Design and usability

Comments

@daxpedda
Copy link
Member

daxpedda commented Dec 25, 2023

Currently, the rwh::WindowHandle we return gets a lifetime to Window. Unfortunately this doesn't really work out because the actual lifetime of the Window isn't connected to it's semantic lifetime. If the EventLoop is exited, all Windows become invalid, therefor making all connected WindowHandles unsound to continue to use.

One simple solution that was proposed in IRC by Ralith is to extend the lifetime of all Windows even after the EventLoop was exited. This might be a viable solution as recreating the EventLoop isn't allowed anyway (except on Web).

For a more "proper" solution, we would have to introduce a lifetime to Window that is connected to the EventLoop. This would require a major API re-design.

Also discussed in:

@daxpedda daxpedda added B - bug Dang, that shouldn't have happened S - api Design and usability C - needs discussion Direction must be ironed out labels Dec 25, 2023
@daxpedda daxpedda added this to the Version 0.30.0 milestone Dec 26, 2023
@notgull
Copy link
Member

notgull commented Dec 27, 2023

Would be best IMO to just keep the display handle alive when a window is alive. Feels more semantically sound. Just keep the Display handle or whatever in an Arc.

@kchibisov
Copy link
Member

You don't have handle on macOS though, that's the issue.

@notgull
Copy link
Member

notgull commented Dec 27, 2023

You don't have handle on macOS though, that's the issue.

My impression for macOS though is that, when the event loop ends, the application exits, effectively preventing the Windows from being accessed. So this isn't a problem there.

@kchibisov
Copy link
Member

I remember there were caveats around that and that's part of the reason we explicitly require drop for windows between run_on_demand iterations.

@notgull
Copy link
Member

notgull commented Dec 27, 2023

For the platforms I know:

  • Windows doesn't really have a "display" object anyways, windows can be manipulated at any time without issue.
  • macOS (and iOS AFAIK) exit the application once the event loop exits, so it shouldn't have this problem.
  • X11 and Wayland keep around the connection to the server in an Arc in the window, so it shouldn't have this problem.
  • The Android window is refcounted internally, I think. So there may be errors but there won't be soundness issues.
  • Web is just checked indexes into a JS array, so it can't violate memory safety.
  • I'm not sure what Redox does but it probably won't cause memory safety issues.

Do you have a link to this discussion? There's probably something I've missed.

@madsmtm
Copy link
Member

madsmtm commented Dec 27, 2023

macOS (and iOS AFAIK) exit the application once the event loop exits

Only iOS.

But on macOS, Window basically contains an Arc, and can safely live beyond EventLoop.

@madsmtm
Copy link
Member

madsmtm commented Jan 27, 2024

For reference: @daxpedda noted in #3367 (comment) under "Nothing Outlives the Event Loop" that one solution could be: the event loop can't be exited without dropping all Windows first, with the drawback that users to have to "track down" all Window handles to be able to exit their application.

Further discussion notes from out meeting last week in here.

Direct Window access: #3434.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B - bug Dang, that shouldn't have happened C - needs discussion Direction must be ironed out S - api Design and usability
Development

No branches or pull requests

4 participants