115: Handle error case for SwapChain::get_next_texture r=kvark a=antonok-edm

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

Co-authored-by: Anton Lazarev <antonok35@gmail.com>
This commit is contained in:
bors[bot]
2019-11-06 03:48:03 +00:00
committed by GitHub
3 changed files with 17 additions and 9 deletions

View File

@@ -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]);
}

View File

@@ -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 });
{

View File

@@ -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,
})
}
}
}