Skip to content

Return helpful error when WebGPU is disabled#9319

Open
emilk wants to merge 4 commits intogfx-rs:trunkfrom
rerun-io:emilk/improve-webgpu-error-msg
Open

Return helpful error when WebGPU is disabled#9319
emilk wants to merge 4 commits intogfx-rs:trunkfrom
rerun-io:emilk/improve-webgpu-error-msg

Conversation

@emilk
Copy link
Copy Markdown
Contributor

@emilk emilk commented Mar 27, 2026

Previously, if WebGPU was disabled in the browser, wgpu would crash with a very unhelpful error message:

panicked at ~/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wgpu-29.0.1/src/backend/webgpu.rs:1126:14:
canvas context is not a GPUCanvasContext: Object { obj: JsValue(GPUCanvasContext), generics: PhantomData<wasm_bindgen::JsValue> }

Tested in Firefox

Copy link
Copy Markdown
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious that we get an non-null object back that simply isn't a GpuCanvasContext and not an error either. Nasty. But I believe it. Curious what that object is for you, would be nice if you could provide that information, but lgtm either way - can't be defensive enough I figure 🤷

@Wumpf Wumpf enabled auto-merge (squash) March 27, 2026 10:07
emilk added a commit to emilk/egui that referenced this pull request Mar 27, 2026
* Fix for emilk/eframe_template#223
* Related: gfx-rs/wgpu#9319

By default, we would only turn on the WebGPU backend on web, which means
browsers without WebGPU support would just crash.

You can still opt-out of all the default `wgpu` features by enabling
`eframe/wgpu_no_default_features` instead of `eframe/wgpu`
auto-merge was automatically disabled March 27, 2026 10:17

Head branch was pushed to by a user without write access

Masterchef365 pushed a commit to Masterchef365/egui that referenced this pull request Apr 3, 2026
* Fix for emilk/eframe_template#223
* Related: gfx-rs/wgpu#9319

By default, we would only turn on the WebGPU backend on web, which means
browsers without WebGPU support would just crash.

You can still opt-out of all the default `wgpu` features by enabling
`eframe/wgpu_no_default_features` instead of `eframe/wgpu`
Copy link
Copy Markdown
Member

@ErichDonGubler ErichDonGubler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, minus a nit I'll fix up myself in a second. PTAL @Wumpf and/or @emilk, WDYT?

.map_err(|actual| crate::CreateSurfaceError {
inner: crate::CreateSurfaceErrorKind::Web(
format!(
"canvas.getContext() returned a value that did not coerce to GPUCanvasContext. This is likely because WebGPU is disabled in this browser. Expected: GPUCanvasContext, Actual: {}",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Let's put code-like things in backticks. Not all wgpu code perfectly does this yet, but we're trying to meet the standard the rest of the Rust ecosystem sets for this.

I'm less certain if it makes sense for the to_string call; I think it's the Web platform's toString, but I'm not positive. So, I'll leave off the comparison printing, but suspect it would also be helpful there.

/me gets off his backtick soap box

Suggested change
"canvas.getContext() returned a value that did not coerce to GPUCanvasContext. This is likely because WebGPU is disabled in this browser. Expected: GPUCanvasContext, Actual: {}",
"`canvas.getContext()` returned a value that did not coerce to `GPUCanvasContext`. This is likely because WebGPU is disabled in this browser. Expected: GPUCanvasContext, Actual: {}",

style: Let's break up this string with concat!(…), so we don't hamstring rustfmt. Case in point: rustfmt would have indented the multiple lines of arguments here, but it didn't because of this.

@ErichDonGubler
Copy link
Copy Markdown
Member

ErichDonGubler commented Apr 3, 2026

Ahhh, but I can't push anything, because org-based forks don't allow maintainer edits. 🤔 Well, here: you can apply the fixups I suggested and applied at cf44334 with git fetch https://github.com/erichdongubler-mozilla/wgpu cf44334d && git branch emilk/improve-webgpu-error-msg FETCH_HEAD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants