You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// # 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.
The text was updated successfully, but these errors were encountered:
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.
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?
create_surface's doc has this,
However, /beginner/tutorial2-surface/#state-new has this note, which says the opposite.
Since the fields of a struct are dropped in declaration order, it'd be nice to have a safety comment in the
State
struct thatsurface
must be declared beforewindow
since some devs might be tempted to reorder the fields.The text was updated successfully, but these errors were encountered: