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

Safety note for create_surface appears off #475

Closed
tbfleming opened this issue May 13, 2023 · 2 comments
Closed

Safety note for create_surface appears off #475

tbfleming opened this issue May 13, 2023 · 2 comments

Comments

@tbfleming
Copy link

create_surface's doc has this,

Safety

  • ...
  • raw_window_handle must remain valid until after the returned Surface is dropped.

However, /beginner/tutorial2-surface/#state-new has this note, which says the opposite.

// # Safety
//
// The surface needs to live as long as the window that created it.
// State owns the window so this should be safe.
let surface = unsafe { instance.create_surface(&window) }.unwrap();

Since the fields of a struct are dropped in declaration order, it'd be nice to have a safety comment in the State struct that surface must be declared before window since some devs might be tempted to reorder the fields.

@sotrh
Copy link
Owner

sotrh commented May 26, 2023

I don't think there's any issues with order in structs AFAIK. I think the unsafety comes with using a surface after a window is destroyed. A situation where I could see this is if you create a surface on one thread and pass it to a different thread.

@tbfleming
Copy link
Author

Does the Surface drop implementation guarantee it doesn't call a native API which uses or drops a native object which requires the window handle isn't already dropped? On all platforms?

@sotrh sotrh closed this as completed in 509dc85 Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants