Remove unwraps in webgpu checking function (#1382)

This commit is contained in:
Dennis Kobert 2023-08-11 10:33:14 +02:00 committed by GitHub
parent 7c1198a1b4
commit 8f586949a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -42,12 +42,15 @@ impl WasmApplicationIo {
pub async fn new() -> Self {
#[cfg(all(feature = "wgpu", target_arch = "wasm32"))]
let executor = if let Some(gpu) = web_sys::window().map(|w| w.navigator().gpu()) {
let request_adapter = js_sys::Reflect::get(&gpu, &wasm_bindgen::JsValue::from_str("requestAdapter")).unwrap();
let function = js_sys::Function::try_from(&request_adapter).unwrap();
let result = function.call0(&gpu);
let request_adapter = || {
let request_adapter = js_sys::Reflect::get(&gpu, &wasm_bindgen::JsValue::from_str("requestAdapter")).ok()?;
let function = js_sys::Function::try_from(&request_adapter)?;
Some(function.call0(&gpu).ok())
};
let result = request_adapter();
match result {
Err(_) => None,
Ok(_) => WgpuExecutor::new().await,
None => None,
Some(_) => WgpuExecutor::new().await,
}
} else {
None