From 198f38347465401e0041cf39142e3b4b9ebfdd06 Mon Sep 17 00:00:00 2001 From: Filipe Rodrigues Date: Sun, 6 Oct 2024 10:05:44 +0100 Subject: [PATCH] Fixed renderer quitting when app was put to sleep. --- zsw-wgpu/src/renderer.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/zsw-wgpu/src/renderer.rs b/zsw-wgpu/src/renderer.rs index 59a2591..e1ecb3b 100644 --- a/zsw-wgpu/src/renderer.rs +++ b/zsw-wgpu/src/renderer.rs @@ -68,8 +68,15 @@ impl WgpuRenderer { pub fn start_render(&self, shared: &WgpuShared) -> Result { // And then get the surface texture // Note: This can block, so we run it under tokio's block-in-place - let surface_texture = tokio::task::block_in_place(|| self.surface.get_current_texture()) - .context("Unable to retrieve current texture")?; + // Note: If the application goes to sleep, this can fail spuriously due to a timeout, + // so we keep retrying. + // TODO: Use an exponential timeout, with a max duration? + let surface_texture = tokio::task::block_in_place(|| loop { + match self.surface.get_current_texture() { + Ok(surface_texture) => break surface_texture, + Err(err) => tracing::warn!(%err, "Unable to retrieve current texture, retrying"), + } + }); let surface_view_descriptor = wgpu::TextureViewDescriptor { label: Some("[zsw] Window surface texture view"), ..wgpu::TextureViewDescriptor::default()