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

Commit cbdd74f

Browse files
Merge #115
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>
2 parents 2c7d43e + dd23e8f commit cbdd74f

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

examples/framework.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ pub fn run<E: Example>(title: &str) {
162162
}
163163
},
164164
event::Event::EventsCleared => {
165-
let frame = swap_chain.get_next_texture();
165+
let frame = swap_chain.get_next_texture()
166+
.expect("Timeout when acquiring next swap chain texture");
166167
let command_buf = example.render(&frame, &device);
167168
queue.submit(&[command_buf]);
168169
}

examples/hello-triangle/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ fn main() {
133133
_ => {}
134134
},
135135
event::Event::EventsCleared => {
136-
let frame = swap_chain.get_next_texture();
136+
let frame = swap_chain.get_next_texture()
137+
.expect("Timeout when acquiring next swap chain texture");
137138
let mut encoder =
138139
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 });
139140
{

src/lib.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,14 +1351,20 @@ impl SwapChain {
13511351
///
13521352
/// When the [`SwapChainOutput`] returned by this method is dropped, the swapchain will present
13531353
/// the texture to the associated [`Surface`].
1354-
pub fn get_next_texture(&mut self) -> SwapChainOutput {
1354+
///
1355+
/// Returns an `Err` if the GPU timed out when attempting to acquire the next texture.
1356+
pub fn get_next_texture(&mut self) -> Result<SwapChainOutput, ()> {
13551357
let output = wgn::wgpu_swap_chain_get_next_texture(self.id);
1356-
SwapChainOutput {
1357-
view: TextureView {
1358-
id: output.view_id,
1359-
owned: false,
1360-
},
1361-
swap_chain_id: &self.id,
1358+
if output.view_id == wgn::Id::ERROR {
1359+
Err(())
1360+
} else {
1361+
Ok(SwapChainOutput {
1362+
view: TextureView {
1363+
id: output.view_id,
1364+
owned: false,
1365+
},
1366+
swap_chain_id: &self.id,
1367+
})
13621368
}
13631369
}
13641370
}

0 commit comments

Comments
 (0)