remotion-dev/remotion · error · Error

Failed to create WebGL shader

Error message

Failed to create WebGL shader

What it means

Thrown by compileShader() in the linear-gradient effect when gl.createShader() returns null. The WebGL2 context exists but refused to allocate a new shader object, which the library treats as fatal because the effect cannot run without one. It is an environment/resource failure, not a shader-source problem.

Source

Thrown at packages/effects/src/linear-gradient.ts:170

	return clamp(dot(uv - uStart, gradient) / gradientLengthSq, 0.0, 1.0);
}

void main() {
	vec2 publicUv = vec2(vUv.x, 1.0 - vUv.y);
	vec4 color = mix(uStartColor, uEndColor, gradientProgress(publicUv));
	fragColor = vec4(color.rgb * color.a, color.a);
}
`;

const compileShader = (
	gl: WebGL2RenderingContext,
	type: number,
	source: string,
): WebGLShader => {
	const shader = gl.createShader(type);
	if (!shader) {
		throw new Error('Failed to create WebGL shader');
	}

	gl.shaderSource(shader, source);
	gl.compileShader(shader);
	if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
		const log = gl.getShaderInfoLog(shader);
		gl.deleteShader(shader);
		throw new Error(
			`Linear gradient shader compile failed: ${log ?? '(no log)'}`,
		);
	}

	return shader;
};

const createProgram = (gl: WebGL2RenderingContext): WebGLProgram => {
	const vs = compileShader(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
	const fs = compileShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Retry the render once — a lost context is frequently transient and recovers on a fresh Chrome process.
  2. Pass an explicit GL backend to the renderer, e.g. set the CLI/config GL to angle with swiftshader: `--gl=angle --angle-backend=swiftshader` (or `chrome` / `swangle`), to guarantee software rendering.
  3. Lower concurrency so fewer WebGL contexts live at once: reduce Remotion's `--concurrency` (Lambda `framesPerLambda` / parallelism) or close other Studio tabs.
  4. Update Chrome/Chromium and GPU drivers on the host; if on Lambda, use a Remotion-published layer that ships a known-good Chrome+SwiftShader.
  5. Check the Chrome log for 'GpuProcess crashed' or 'ContextResult::kTransientFailure' to confirm a GPU-process problem rather than an app bug.

Example fix

// before (default GL, fails on a GPU-less host)
//   npx remotion render MyComp out.mp4

// after — force software GL so createShader always succeeds
//   npx remotion render MyComp out.mp4 \
//       --gl=angle --angle-backend=swiftshader
Defensive patterns

Strategy: retry

Validate before calling

// Feature-detect WebGL2 before mounting a GPU effect — createShader returning null
// implies the context is failing even if getContext succeeded.
function supportsWebGL2ShaderAlloc(canvas: HTMLCanvasElement): boolean {
  const gl = canvas.getContext('webgl2');
  if (!gl) return false;
  const probe = gl.createShader(gl.VERTEX_SHADER);
  const ok = probe !== null;
  if (probe) gl.deleteShader(probe);
  gl.getExtension?.('loseContext')?.loseContext?.();
  return ok;
}

Try / catch

// WebGL resource failures are best treated as transient — retry once on a fresh worker.
try {
  renderWithLinearGradient();
} catch (err) {
  if (err instanceof Error && err.message === 'Failed to create WebGL shader') {
    // restart the Chrome/worker context, then retry exactly once
    await restartRendererWorker();
    renderWithLinearGradient();
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: Calling linearGradient() in a composition that gets rendered or previewed when the underlying WebGL2 context is lost, GPU memory is exhausted, or the process has exceeded the browser's active-context limit (~16). Also occurs in headless Chrome launched without a working GL backend (no SwiftShader/ANGLE).

Common situations: Remotion Lambda/serverless renders where the Chrome GPU process crashed or was culled; local renders with --gl set to a backend the host does not support; many concurrent Studio previews or Player instances each grabbing a context; outdated GPU drivers on the render machine.

Related errors


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