diff options
Diffstat (limited to 'ext/webgpu')
-rw-r--r-- | ext/webgpu/byow.rs | 4 |
1 files changed, 3 insertions, 1 deletions
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<ResourceId, AnyError> { - let instance = state.borrow::<super::Instance>(); + let instance = state.try_borrow::<super::Instance>().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 |