remotion-dev/remotion · critical · Error

Failed to create WebGL vertex array

Error message

Failed to create WebGL vertex array

What it means

Thrown by `setupBarrelDistortion` when `gl.createVertexArray()` returns `null`. The VAO holds the fullscreen-quad vertex attribute binding for the distortion pass. A null result means the GL implementation could not allocate the VAO object — typically a context-loss or resource-limit condition rather than a usage mistake.

Source

Thrown at packages/effects/src/barrel-distortion/barrel-distortion-runtime.ts:110

export const setupBarrelDistortion = (
	target: HTMLCanvasElement,
): BarrelDistortionState => {
	const gl = target.getContext('webgl2', {
		premultipliedAlpha: true,
		alpha: true,
		preserveDrawingBuffer: true,
	});
	if (!gl) {
		throw createWebGL2ContextError('barrel distortion effect');
	}

	gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);

	const program = createProgram(gl, BARREL_DISTORTION_VS, BARREL_DISTORTION_FS);

	const vao = gl.createVertexArray();
	if (!vao) {
		throw new Error('Failed to create WebGL vertex array');
	}

	gl.bindVertexArray(vao);

	const data = new Float32Array([
		-1, -1, 0, 0, 1, -1, 1, 0, -1, 1, 0, 1, 1, 1, 1, 1,
	]);

	const vbo = gl.createBuffer();
	if (!vbo) {
		throw new Error('Failed to create WebGL buffer');
	}

	gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
	gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);

	gl.enableVertexAttribArray(0);
	gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 16, 0);

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Check `gl.isContextLost()` before setup; if true, await context restoration and retry.
  2. Limit the number of concurrently active WebGL2 effects so VAO allocations are not exhausted.
  3. Call `cleanupBarrelDistortion` on unused effect states to free their VAOs.
  4. Verify hardware acceleration is available in the rendering environment.

Example fix

if (gl.isContextLost()) {
  // wait for webglcontextrestored, then re-run setupBarrelDistortion
} else {
  const state = setupBarrelDistortion(canvas);
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (gl.isContextLost()) { /* skip setup */ }

Try / catch

try {
  const state = setupBarrelDistortion(canvas);
} catch (err) {
  if (/Failed to create WebGL vertex array/.test(err.message)) {
    // await context restore, then reinitialize
  } else { throw err; }
}

Prevention

When it happens

Trigger: Fires at barrel-distortion setup (line 108-110) when `gl.createVertexArray()` yields null, immediately after the program is created and before the VBO.

Common situations: The WebGL2 context was lost mid-setup (GPU reset, tab crash, too many contexts); the GL driver enforces a low VAO cap that has been exhausted by other effects/canvases sharing the process.

Related errors


AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12). Data as JSON: /api/errors/38f3a243e8fc05ff. Report an issue: GitHub.