diff options
author | 2024-03-07 23:25:24 +0100 | |
---|---|---|
committer | 2024-03-07 23:25:24 +0100 | |
commit | ecf42b97df85df25b1b825f37adfeb00f658f6ee (patch) | |
tree | 43ea058c8b7d0b4a13f9fe3ad7015efeea94ed48 /renderer | |
parent | 1bb5a1b9a23e1c4739430ac87ca33b06c2f4d9df (diff) | |
download | iced-ecf42b97df85df25b1b825f37adfeb00f658f6ee.tar.gz iced-ecf42b97df85df25b1b825f37adfeb00f658f6ee.tar.bz2 iced-ecf42b97df85df25b1b825f37adfeb00f658f6ee.zip |
Fix `block_on` in `iced_wgpu` hanging Wasm builds
Diffstat (limited to 'renderer')
-rw-r--r-- | renderer/src/compositor.rs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/renderer/src/compositor.rs b/renderer/src/compositor.rs index dc2c50ff..c23a814c 100644 --- a/renderer/src/compositor.rs +++ b/renderer/src/compositor.rs @@ -4,6 +4,7 @@ use crate::graphics::{Error, Viewport}; use crate::{Renderer, Settings}; use std::env; +use std::future::Future; pub enum Compositor { TinySkia(iced_tiny_skia::window::Compositor), @@ -25,22 +26,25 @@ impl crate::graphics::Compositor for Compositor { fn new<W: Window + Clone>( settings: Self::Settings, compatible_window: W, - ) -> Result<Self, Error> { + ) -> impl Future<Output = Result<Self, Error>> { let candidates = Candidate::list_from_env().unwrap_or(Candidate::default_list()); - let mut error = Error::GraphicsAdapterNotFound; + async move { + let mut error = Error::GraphicsAdapterNotFound; - for candidate in candidates { - match candidate.build(settings, compatible_window.clone()) { - Ok(compositor) => return Ok(compositor), - Err(new_error) => { - error = new_error; + for candidate in candidates { + match candidate.build(settings, compatible_window.clone()).await + { + Ok(compositor) => return Ok(compositor), + Err(new_error) => { + error = new_error; + } } } - } - Err(error) + Err(error) + } } fn create_renderer(&self) -> Self::Renderer { @@ -225,7 +229,7 @@ impl Candidate { ) } - fn build<W: Window>( + async fn build<W: Window>( self, settings: Settings, _compatible_window: W, @@ -252,7 +256,8 @@ impl Candidate { ..iced_wgpu::Settings::from_env() }, _compatible_window, - )?; + ) + .await?; Ok(Compositor::Wgpu(compositor)) } |