Skip to content

Commit f069c58

Browse files
committed
examples/runners/wgpu: avoid holding onto to multiple surfaces at the same time.
1 parent 211b7fc commit f069c58

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

examples/runners/wgpu/src/graphics.rs

+19
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,25 @@ async fn run(
164164
event_loop_window_target.set_control_flow(ControlFlow::Wait);
165165
match event {
166166
Event::Resumed => {
167+
// Avoid holding onto to multiple surfaces at the same time
168+
// (as it's undetected and can confusingly break e.g. Wayland).
169+
//
170+
// FIXME(eddyb) create the window and `wgpu::Surface` on either
171+
// `Event::NewEvents(StartCause::Init)`, or `Event::Resumed`,
172+
// which is becoming recommended on (almost) all platforms, see:
173+
// - https://github.com/rust-windowing/winit/releases/tag/v0.30.0
174+
// - https://github.com/gfx-rs/wgpu/blob/v23/examples/src/framework.rs#L139-L161
175+
// (note wasm being handled differently due to its `<canvas>`)
176+
if let Ok((_, surface_config)) = &surface_with_config {
177+
// HACK(eddyb) can't move out of `surface_with_config` as
178+
// it's a closure capture, and also the `Err(_)` variant
179+
// has a payload so that needs to be filled with something.
180+
let filler = Err(SurfaceCreationPending {
181+
preferred_format: surface_config.format,
182+
});
183+
drop(std::mem::replace(&mut surface_with_config, filler));
184+
}
185+
167186
let new_surface = instance.create_surface(&window)
168187
.expect("Failed to create surface from window (after resume)");
169188
surface_with_config = Ok(auto_configure_surface(

0 commit comments

Comments
 (0)