diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2024-06-13 19:04:32 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-13 13:34:32 +0000 |
commit | e4f3ed82ee2f3a9f68b159c2817acd2f6a9f35aa (patch) | |
tree | 0d274fb4b50cf5232a4f6f199ee88ae3f5ef215b /ext/webgpu/byow.rs | |
parent | abe9953829f0c5174ffd7668d9903785b7a7e4c9 (diff) |
fix(ext/webgpu): fix surface creation panic when adapter not initialized (#24201)
Fixes https://github.com/denoland/deno/issues/23433
Diffstat (limited to 'ext/webgpu/byow.rs')
-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 |