From e4f3ed82ee2f3a9f68b159c2817acd2f6a9f35aa Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 13 Jun 2024 19:04:32 +0530 Subject: 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(-) (limited to 'ext') diff --git a/ext/webgpu/byow.rs b/ext/webgpu/byow.rs index 2d77cff6e..fa3ce2d96 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 -- cgit v1.2.3