From 80b592b52951fba773c7929544c039c7dbc26d56 Mon Sep 17 00:00:00 2001 From: Pearl L Date: Sun, 8 Oct 2023 13:27:59 -0700 Subject: [PATCH] fix unwrap crash when render surface is unavailable (0 height etc) --- vger/src/lib.rs | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/vger/src/lib.rs b/vger/src/lib.rs index edcc567e..c7c86caf 100644 --- a/vger/src/lib.rs +++ b/vger/src/lib.rs @@ -386,25 +386,26 @@ impl Renderer for VgerRenderer { } fn finish(&mut self) { - let frame = self.surface.get_current_texture().unwrap(); - let texture_view = frame - .texture - .create_view(&wgpu::TextureViewDescriptor::default()); - let desc = wgpu::RenderPassDescriptor { - label: None, - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &texture_view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(wgpu::Color::WHITE), - store: true, - }, - })], - depth_stencil_attachment: None, - }; - - self.vger.encode(&desc); - frame.present(); + if let Ok(frame) = self.surface.get_current_texture() { + let texture_view = frame + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); + let desc = wgpu::RenderPassDescriptor { + label: None, + color_attachments: &[Some(wgpu::RenderPassColorAttachment { + view: &texture_view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::WHITE), + store: true, + }, + })], + depth_stencil_attachment: None, + }; + + self.vger.encode(&desc); + frame.present(); + } } }