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

Lifetime of Context #75

Closed
daxpedda opened this issue Feb 28, 2023 · 4 comments
Closed

Lifetime of Context #75

daxpedda opened this issue Feb 28, 2023 · 4 comments

Comments

@daxpedda
Copy link
Member

I know this is not released yet, but after #64 Context and Surface were split.

How long is Context supposed to be kept alive? Does it need to stay alive as long as Surface, or can it be safely dropped while Surface is kept around and used?

@ids1024
Copy link
Member

ids1024 commented Feb 28, 2023

Anything from the Context that's still needed is reference counted, so the Context struct can be dropped.

Though the underlying RawDisplayHandle and RawWindowHandle must remain valid for the lifetime of the Surface, or its undefined behavior.

@daxpedda
Copy link
Member Author

Thanks!

@kpreid
Copy link
Contributor

kpreid commented Jun 12, 2023

I'd like to propose reopening this issue, as this could be specified more clearly in the documentation for everyone to see. The current safety documentation for Surface::new says:

Ensure that the provided objects are valid to draw a 2D buffer to, and are valid for the lifetime of the Context

which could be interpreted as anything from @daxpedda's “stay alive as long as Surface” to the perverse “it doesn't matter if the handle stops being valid while you're still using the Surface, as long as you drop the Context first so its 'lifetime' has ended”. (And “the lifetime of” isn't probably what you mean either, since the lifetime of the &W reference will most likely end before the surface is done.)

(I also wish "the provided objects are valid to draw a 2D buffer to" was phrased as something that the author of a cross-platform program finds actionable — what documentation should they read to know what it means? But that's not this issue.)

This is a little nitpicky, but I think that it's important to help users writing unsafe code by making it easy to understand what requirements they must uphold — or many of them will just give up and proceed sloppily.

@madsmtm madsmtm reopened this Jun 12, 2023
@notgull
Copy link
Member

notgull commented Nov 15, 2023

This is now fixed as of #132

@notgull notgull closed this as completed Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants