Winit 0.30 + wgpu 0.20 init lifetime issue

There is a way to set up the wgpu::Surface without any unsafe or lifetime restrictions. All you have to do is put the winit window in an Arc, which then can be cloned and passed to wgpu::Instance::create_surface(). This ensures that the window exists for as long as the surface does.

let window = Arc::new(window);
let surface = instance.create_surface(Arc::clone(&window))?;
// save and use original `window` as needed...

There is no need to contort the control-flow of your program, or use unsafe code, to satisfy wgpu.

2 Likes