From 6f2ad6e1e2215f4c422e92d2bf7ecbe6d652171a Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 13 Jun 2024 19:04:32 +0530 Subject: [PATCH] fix(ext/webgpu): fix surface creation panic when adapter not initialized (#24201) Fixes https://github.com/denoland/deno/issues/23433 --- ext/webgpu/byow.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ext/webgpu/byow.rs b/ext/webgpu/byow.rs index 2d77cff6e2..fa3ce2d966 100644 --- a/ext/webgpu/byow.rs +++ b/ext/webgpu/byow.rs @@ -24,7 +24,9 @@ pub fn op_webgpu_surface_create( p1: *const c_void, p2: *const c_void, ) -> Result { - let instance = state.borrow::(); + let instance = state.try_borrow::().ok_or_else(|| { + type_error("Cannot create surface outside of WebGPU context. Did you forget to call `navigator.gpu.requestAdapter()`?") + })?; // Security note: // // The `p1` and `p2` parameters are pointers to platform-specific window