Skip to content

Surface Drop order #3991

Jul 29, 2023 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

This could be wrong as I haven't actually looked at the code but to my understanding, the Surface contains several different unsafe references to the window that assume that it is still alive. This includes a raw pointer to the underlying memory in VRAM where the window's pixel buffer resides. Trying to, say, render to this underlying texture after the window has closed and the memory may be freed would be Undefined Behavior. There's a reason why creating a WGPU Surface from a Winit Window is considered Unsafe.

In short, if a Surface persists after its window becomes invalid, any operations involving it will be Undefined Behavior.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@JustAnotherCodemonkey
Comment options

@sotrh
Comment options

@JustAnotherCodemonkey
Comment options

Answer selected by sotrh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants