remotion-dev/remotion · critical · Error

Failed to create WebGL shader

Error message

Failed to create WebGL shader

What it means

In `compileShader`, `gl.createShader(type)` returned `null`. The WebGL2 spec returns null only on context loss or when arguments are invalid; here the type is always a valid constant. Practically this means the WebGL2 context is lost, the GPU resources are exhausted, or the context is in a broken state. This is an environment/resource failure, not a code bug in your call.

Source

Thrown at packages/brand/src/effects/metallic-swirl-effect.ts:462

		uBackgroundColor,
		color,
		clamp(luminance * 6.0, 0.0, 1.0)
	);
	vec3 result = uMode == 1 ? generated : mix(sourceRgb, generated, uOpacity);
	float alpha = uMode == 1 ? source.a * uOpacity : source.a;

	fragColor = vec4(result * alpha, alpha);
}
`;

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(
			`Metallic swirl shader compile failed: ${log ?? '(no log)'}`,
		);
	}

	return shader;
};

const linkProgram = (
	gl: WebGL2RenderingContext,
	vs: WebGLShader,

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Verify WebGL2 is available in the target browser/machine (run a getContext('webgl2') check).
  2. Reduce the number of simultaneously mounted effects to free GPU resources.
  3. Update GPU drivers / use a hardware-accelerated browser.
  4. For headless rendering, ensure the renderer uses a GPU-backed Chrome (Remotion's headless shell) rather than a software-only fallback.
Defensive patterns

Strategy: try-catch

Validate before calling

// Probe WebGL2 availability before mounting the effect.
const supportsWebGL2 = (): boolean => {
  try {
    const c = document.createElement('canvas');
    const gl = c.getContext('webgl2');
    return !!gl;
  } catch {
    return false;
  }
};
if (!supportsWebGL2()) {
  // show a fallback or skip the effect
}

Type guard

const hasHealthyWebGL2 = (canvas: HTMLCanvasElement): boolean => {
  const gl = canvas.getContext('webgl2');
  return !!gl && !gl.isContextLost();
};

Try / catch

try {
  metallicSwirl({speed: 1})(...);
} catch (err) {
  if (err instanceof Error && /Failed to create WebGL shader/.test(err.message)) {
    // fall back to a non-WebGL effect or notify the user
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: Rendering on a machine without working WebGL2 drivers; GPU memory exhausted after creating many effects/canvases; context lost due to a driver crash, system sleep/wake, or too many contexts; headless rendering without GPU support (e.g. software WebGL fallback failing).

Common situations: Long-running Studio sessions that leak contexts; rendering farms or CI without GPU; older drivers or virtual machines; many simultaneous metallic-swirl effects across multiple sequences.

Related errors


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