Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Merge #115
Browse files Browse the repository at this point in the history
115: Handle error case for SwapChain::get_next_texture r=kvark a=antonok-edm

Updates `SwapChain::get_next_texture` to account for gfx-rs/wgpu#369. Otherwise, an invalid `Id` is returned and may cause confusing errors.

Co-authored-by: Anton Lazarev <antonok35@gmail.com>
  • Loading branch information
bors[bot] and antonok-edm authored Nov 6, 2019
2 parents 2c7d43e + dd23e8f commit cbdd74f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ pub fn run<E: Example>(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]);
}
Expand Down
3 changes: 2 additions & 1 deletion examples/hello-triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
{
Expand Down
20 changes: 13 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SwapChainOutput, ()> {
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,
})
}
}
}

0 comments on commit cbdd74f

Please sign in to comment.