Skip to content

fix(webgl): explain WebGL2-context failures with a troubleshooting hint#251

Merged
korbinian90 merged 1 commit into
mainfrom
claude/upbeat-gagarin-ea2da6
Jun 19, 2026
Merged

fix(webgl): explain WebGL2-context failures with a troubleshooting hint#251
korbinian90 merged 1 commit into
mainfrom
claude/upbeat-gagarin-ea2da6

Conversation

@korbinian90

Copy link
Copy Markdown
Collaborator

What

The on-canvas error panel now adds a short, targeted explanation and a "How to fix" link when WebGL2 context creation fails, instead of showing only niivue's raw message. Also adds a Troubleshooting section to the VS Code extension README.

Refs #236.

Why

Reported on Linux in VS Code and reproduced on a second Debian machine: the same extension version that works on Windows fails with "Failed to load image: unable to get WebGL context. Maybe the browser doesn't support WebGL2."

The cause is environmental, not a bug in the extension. Recent Chromium (context creation starts failing around Chromium 144, which reached users via the VS Code Electron bump) removed the automatic fallback to software WebGL (SwiftShader). When the webview has no working hardware WebGL2 (common with the snap build of VS Code, missing or blocklisted GPU drivers, or some Wayland setups), getContext('webgl2') returns null. Windows is unaffected because its software fallback is Direct3D WARP, which Chromium does not gate.

niivue's message already surfaced in the error panel, but on its own it reads like a corrupt file. This change keeps that message and appends one line clarifying it is an environment/GPU issue, with a pointer to the fix.

Changes

  • packages/niivue-react/src/components/Volume.tsx: in the existing nv.loadError panel, when the message is exactly unable to get WebGL context, render a concise note plus a "How to fix" link to WebGL2 context not working everywhere #236. Detection is a precise substring match. Every app mounts the shared Container -> Volume, so the PWA, Jupyter, Streamlit, and desktop apps inherit it too.
  • apps/vscode/README.md: Troubleshooting section with the recommended fix (restore hardware acceleration; replace the snap with the official .deb) and the temporary enable-unsafe-swiftshader argv.json workaround, flagged as temporary since Chromium is removing it.
  • Changeset (patch).

Notes for reviewers

  • Deliberately minimal: no capability probe, no separate component, no host detection, no new message protocol. The error is already displayed; this only augments it.
  • prettier --write was intentionally not run on the touched existing files (repo source is not Prettier-conformant at baseline), so the diff is intent-only.
  • Verified locally: typecheck (all packages), @niivue/react and niivue unit tests, and lint all pass.

🤖 Generated with Claude Code

When the browser/Electron webview cannot create a WebGL2 context, niivue
throws "unable to get WebGL context. Maybe the browser doesn't support
WebGL2." which already surfaces in the on-canvas error panel. On its own
that message reads like a corrupt file, when it is actually an environment
issue (no hardware acceleration, e.g. the VS Code snap build, missing GPU
drivers, or recent Chromium dropping the automatic SwiftShader fallback).

- Volume error panel: when the message is exactly that WebGL2-context
  error, append a short note clarifying it is an environment issue (not the
  file) plus a "How to fix" link to issue #236. Every app that mounts the
  shared viewer inherits this.
- VS Code README: add a Troubleshooting section with the recommended fix
  (restore hardware acceleration) and the temporary enable-unsafe-swiftshader
  workaround.

Refs #236

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

🚀 PWA Preview Deployment

Your PWA preview has been deployed!

Preview URL: https://niivue.github.io/niivue-vscode/pr-251/


This preview will be updated automatically when you push new commits to this PR.

github-actions Bot added a commit that referenced this pull request Jun 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report

coverage

Overall line coverage: 42.1%

Package Statements Branches Functions Lines
Shared core (packages/niivue-react) 45.9% 46.8% (−0.1) 44.8% 46.6%
apps/pwa 28.9% 33.3% 52.9% 30.2%
apps/jupyter 14.4% 15.9% 14.9% 14.5%
apps/streamlit 17.8% 5.3% 18.5% 17.7%
apps/vscode 38.7% 39.6% 18.9% 38.1%
apps/desktop-tauri 81.8% 59.1% 78.9% 84.3%

📊 View full report →

@korbinian90 korbinian90 merged commit a3e3be2 into main Jun 19, 2026
13 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🧹 PWA Preview Cleanup

The preview deployment for this PR has been removed.

github-actions Bot added a commit that referenced this pull request Jun 19, 2026
github-actions Bot added a commit that referenced this pull request Jun 19, 2026
korbinian90 added a commit that referenced this pull request Jun 19, 2026
Reconcile #250 (brand menu + NVDocument Save/Load split button) and #251
(WebGL2 context-error hint) with the v1.0 core migration.

Resolution (Menu.tsx conflicts + the auto-merged document path, kept on the
v1 API):
- Keep #250's "NVDocument" Save/Load split button, but Save uses
  nv.serializeDocument() (v1 CBOR), not the removed nv.json(). The dropdown
  becomes Save / Save as JSON / Load, combining #250's Load entry with the
  migration's JSON export.
- events.ts and Volume.tsx auto-merged; #250's loadDocumentEvent coexists
  with the v1 ExtendedNiivue, loaders, and event wiring.
- Migrate #250's new MenuBrandDocument.test.tsx to the v1 niivue surface
  (default NiiVueGPU export, serializeDocument, header-based metadata) and
  add a Save-as-JSON assertion.

turbo type-check 8/8; @niivue/react 157 unit tests pass; react + pwa build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

1 participant