BabylonJS/Babylon.js · error
DumpData: No WebGL context available. Cannot dump data.
Error message
DumpData: No WebGL context available. Cannot dump data.
What it means
DumpTools' pure (DOM-independent) dump path lazily imports ThinEngine to get a GPU context for encoding dump data. If ThinEngine.IsSupported is false — no usable WebGL — there is no way to encode the dump, so the library throws this explicit error instead of failing later with an opaque context error.
Source
Thrown at packages/dev/core/src/Misc/dumpTools.pure.ts:39
renderer: EffectRenderer;
wrapper: EffectWrapper;
};
};
let ResourcesPromise: Promise<DumpResources> | null = null;
async function _CreateDumpResourcesAsync(): Promise<DumpResources> {
// Create a compatible canvas. Prefer an HTMLCanvasElement if possible to avoid alpha issues with OffscreenCanvas + WebGL in many browsers.
const canvas = (EngineStore.LastCreatedEngine?.createCanvas(100, 100) ?? new OffscreenCanvas(100, 100)) as HTMLCanvasElement | OffscreenCanvas; // will be resized later
if (canvas instanceof OffscreenCanvas) {
Logger.Warn("DumpData: OffscreenCanvas will be used for dumping data. This may result in lossy alpha values.");
}
// If WebGL via ThinEngine is not available, we cannot encode the data.
// If https://github.com/whatwg/html/issues/10142 is resolved, we can migrate to just BitmapRenderer and avoid an engine dependency altogether.
const { ThinEngine: thinEngineClass } = await import("../Engines/thinEngine.pure");
if (!thinEngineClass.IsSupported) {
throw new Error("DumpData: No WebGL context available. Cannot dump data.");
}
const options = {
preserveDrawingBuffer: true,
depth: false,
stencil: false,
alpha: true,
premultipliedAlpha: false,
antialias: false,
failIfMajorPerformanceCaveat: false,
};
const engine = new thinEngineClass(canvas, false, options);
// remove this engine from the list of instances to avoid using it for other purposes
EngineStore.Instances.pop();
// However, make sure to dispose it when no other engines are left
EngineStore.OnEnginesDisposedObservable.add((e) => {
// guaranteed to run when no other instances are left
View on GitHub (pinned to 0592b347b8)
Solutions
- Run in an environment with WebGL available, or enable SwiftShader/llvmpipe software GL in headless CI (e.g. --use-gl=swiftshader in Chromium)
- Check ThinEngine.IsSupported (or create an engine and check engine.isSupported) before attempting a dump and surface a friendly message instead
- Use a non-WebGL dump path if available (e.g. plain canvas 2D rendering of the data) instead of the GPU-encoded dump tools
- If WebGL worked before, investigate context loss / driver blocklist (chrome://gpu) and request a new context
Example fix
// before
await DumpDataAsync(texture, dumpOptions);
// after
if (!ThinEngine.IsSupported) {
console.warn('WebGL unavailable; skipping dump');
} else {
await DumpDataAsync(texture, dumpOptions);
} Defensive patterns
Strategy: try-catch
Validate before calling
const { ThinEngine } = await import('../Engines/thinEngine.pure');
if (!ThinEngine.IsSupported) {
throw new Error('WebGL is not available in this environment; dump tools cannot run');
} Type guard
function webglAvailable(): boolean {
try {
const c = document.createElement('canvas');
return !!(c.getContext('webgl2') || c.getContext('webgl'));
} catch {
return false;
}
} Try / catch
try {
await DumpDataAsync(target, options);
} catch (e) {
if (e instanceof Error && e.message.includes('No WebGL context available')) {
console.warn('Skipping dump: WebGL not supported in this environment');
} else {
throw e;
}
} Prevention
- Feature-check WebGL (ThinEngine.IsSupported or canvas.getContext('webgl')) before enabling dump features
- In headless CI, launch browsers with software GL (SwiftShader) enabled
- Handle WebGL context-loss events and re-check support before re-dumping
- Provide a CPU/canvas fallback rendering path when GPU encoding is unavailable
When it happens
Trigger: Calling dump-data APIs (e.g. DumpData/DumpDataAsync via _CreateDumpResourcesAsync) in an environment without WebGL support — headless Node, workers with no canvas/GL, browsers with WebGL disabled, or after a context-loss.
Common situations: Running screenshot/dump tests in CI (headless, no GPU or no swiftshader); WebGL blocked by browser flags or driver blocklists; using the pure dump tools outside a browser page that provides a WebGL context.
Related errors
- WebGL not supported
- Atmosphere is not supported on WebGL ${engine.version}.
- Instanced arrays are required for MSDF text rendering.
- Unable to create multi sampled framebuffer
- Invalid Space Warp framebuffer
AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30).
Data as JSON: /api/errors/c215f74090685fab.
Report an issue: GitHub.