diff --git a/ext/webgpu/byow.rs b/ext/webgpu/byow.rs index 2d77cff6e22e9b..fa3ce2d966d434 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