Skip to content

Commit

Permalink
examples/runners/wgpu: avoid holding onto to multiple surfaces at the…
Browse files Browse the repository at this point in the history
… same time.
  • Loading branch information
eddyb committed Dec 18, 2024
1 parent 211b7fc commit f069c58
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions examples/runners/wgpu/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,25 @@ async fn run(
event_loop_window_target.set_control_flow(ControlFlow::Wait);
match event {
Event::Resumed => {
// Avoid holding onto to multiple surfaces at the same time
// (as it's undetected and can confusingly break e.g. Wayland).
//
// FIXME(eddyb) create the window and `wgpu::Surface` on either
// `Event::NewEvents(StartCause::Init)`, or `Event::Resumed`,
// which is becoming recommended on (almost) all platforms, see:
// - https://github.com/rust-windowing/winit/releases/tag/v0.30.0
// - https://github.com/gfx-rs/wgpu/blob/v23/examples/src/framework.rs#L139-L161
// (note wasm being handled differently due to its `<canvas>`)
if let Ok((_, surface_config)) = &surface_with_config {
// HACK(eddyb) can't move out of `surface_with_config` as
// it's a closure capture, and also the `Err(_)` variant
// has a payload so that needs to be filled with something.
let filler = Err(SurfaceCreationPending {
preferred_format: surface_config.format,
});
drop(std::mem::replace(&mut surface_with_config, filler));
}

let new_surface = instance.create_surface(&window)
.expect("Failed to create surface from window (after resume)");
surface_with_config = Ok(auto_configure_surface(
Expand Down

0 comments on commit f069c58

Please sign in to comment.