diff --git a/examples/framework.rs b/examples/framework.rs index efdd3b52c..1d96cb096 100644 --- a/examples/framework.rs +++ b/examples/framework.rs @@ -162,7 +162,8 @@ pub fn run(title: &str) { } }, event::Event::EventsCleared => { - let frame = swap_chain.get_next_texture(); + let frame = swap_chain.get_next_texture() + .expect("Timeout when acquiring next swap chain texture"); let command_buf = example.render(&frame, &device); queue.submit(&[command_buf]); } diff --git a/examples/hello-triangle/main.rs b/examples/hello-triangle/main.rs index 45d64ead1..d363d3fb5 100644 --- a/examples/hello-triangle/main.rs +++ b/examples/hello-triangle/main.rs @@ -133,7 +133,8 @@ fn main() { _ => {} }, event::Event::EventsCleared => { - let frame = swap_chain.get_next_texture(); + let frame = swap_chain.get_next_texture() + .expect("Timeout when acquiring next swap chain texture"); let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 }); { diff --git a/src/lib.rs b/src/lib.rs index a1b8b581a..e55b17fde 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1351,14 +1351,20 @@ impl SwapChain { /// /// When the [`SwapChainOutput`] returned by this method is dropped, the swapchain will present /// the texture to the associated [`Surface`]. - pub fn get_next_texture(&mut self) -> SwapChainOutput { + /// + /// Returns an `Err` if the GPU timed out when attempting to acquire the next texture. + pub fn get_next_texture(&mut self) -> Result { let output = wgn::wgpu_swap_chain_get_next_texture(self.id); - SwapChainOutput { - view: TextureView { - id: output.view_id, - owned: false, - }, - swap_chain_id: &self.id, + if output.view_id == wgn::Id::ERROR { + Err(()) + } else { + Ok(SwapChainOutput { + view: TextureView { + id: output.view_id, + owned: false, + }, + swap_chain_id: &self.id, + }) } } }