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

Handle error case for SwapChain::get_next_texture #115

Merged
merged 1 commit into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should follow up with a better error here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're treating a zero-valued Id as an error, I'm not sure how you'd distinguish between any different errors that might occur. I figured the doc comment snippet is good enough until there's a more specific error-reporting mechanism in wgpu-native.

} else {
Ok(SwapChainOutput {
view: TextureView {
id: output.view_id,
owned: false,
},
swap_chain_id: &self.id,
})
}
}
}