Surface Drop
order
#3991
-
Had a question on my tutorial regarding whether the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
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. |
Beta Was this translation helpful? Give feedback.
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.