Skip to content

Commit d9b3d60

Browse files
committed
return Result instead of panic
1 parent b8d26c9 commit d9b3d60

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

wgpu-native/src/swap_chain.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,16 @@ pub struct SwapChainOutput {
128128
pub view_id: TextureViewId,
129129
}
130130

131+
#[derive(Debug)]
132+
pub enum SwapChainGetNextTextureError {
133+
GpuProcessingTimeout,
134+
}
135+
131136
pub fn swap_chain_get_next_texture<B: GfxBackend>(
132137
global: &Global,
133138
swap_chain_id: SwapChainId,
134139
view_id_in: Input<TextureViewId>,
135-
) -> SwapChainOutput {
140+
) -> Result<SwapChainOutput, SwapChainGetNextTextureError> {
136141
let hub = B::hub(global);
137142
let mut token = Token::root();
138143

@@ -148,7 +153,7 @@ pub fn swap_chain_get_next_texture<B: GfxBackend>(
148153
match unsafe { suf.acquire_image(FRAME_TIMEOUT_MS * 1_000_000) } {
149154
Ok(surface_image) => surface_image,
150155
Err(hal::window::AcquireError::Timeout) => {
151-
panic!("GPU took too much time processing last frames :(");
156+
return Err(SwapChainGetNextTextureError::GpuProcessingTimeout);
152157
}
153158
Err(e) => {
154159
log::warn!("acquire_image() failed ({:?}), reconfiguring swapchain", e);
@@ -197,13 +202,13 @@ pub fn swap_chain_get_next_texture<B: GfxBackend>(
197202
ref_count,
198203
});
199204

200-
SwapChainOutput { view_id }
205+
Ok(SwapChainOutput { view_id })
201206
}
202207

203208
#[cfg(feature = "local")]
204209
#[no_mangle]
205210
pub extern "C" fn wgpu_swap_chain_get_next_texture(swap_chain_id: SwapChainId) -> SwapChainOutput {
206-
gfx_select!(swap_chain_id => swap_chain_get_next_texture(&*GLOBAL, swap_chain_id, PhantomData))
211+
gfx_select!(swap_chain_id => swap_chain_get_next_texture(&*GLOBAL, swap_chain_id, PhantomData)).unwrap()
207212
}
208213

209214
pub fn swap_chain_present<B: GfxBackend>(global: &Global, swap_chain_id: SwapChainId) {

0 commit comments

Comments
 (0)