remotion-dev/remotion · error · Error

Failed to create shader

Error message

Failed to create shader

What it means

The white noise effect compiles its vertex/fragment shaders via gl.createShader; if the GL context returns null it cannot build the program and throws. Because the shader source is a compile-time constant in the library, a null shader object is always a context/resource problem (lost context, object limit, software renderer), never a shader-syntax or user-input issue.

Source

Thrown at packages/effects/src/white-noise.ts:109

}

void main() {
	vec4 color = texture(uSource, vUv);
	float noise = random(gl_FragCoord.xy);
	vec3 unpremultiplied = color.a == 0.0 ? vec3(0.0) : color.rgb / color.a;
	vec3 mixed = mix(unpremultiplied, vec3(noise), uAmount);
	fragColor = vec4(mixed * 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 shader');
	}

	gl.shaderSource(shader, source);
	gl.compileShader(shader);

	if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
		const info = gl.getShaderInfoLog(shader) ?? 'Unknown shader compile error';
		gl.deleteShader(shader);
		throw new Error(info);
	}

	return shader;
};

const createProgram = (
	gl: WebGL2RenderingContext,
	vertexSource: string,
	fragmentSource: string,

View on GitHub (pinned to 78fe4bb3fd)

Solutions

  1. Probe WebGL2 availability and context health before applying whiteNoise().
  2. Render headless with Remotion's bundled Chrome and its enabled software-GPU flags; avoid --disable-gpu overrides.
  3. Cut the number of concurrently-mounted WebGL effects to free GL object slots.
  4. Recreate the composition after webglcontextlost so setup runs against a fresh context.
  5. Move rendering to an environment with a functional GPU / updated drivers.

Example fix

// before
import {whiteNoise} from '@remotion/effects';
<VideoEffects effects={[whiteNoise({amount: 0.4})]} />

// after: only attach the effect when WebGL2 is healthy
const gl = document.createElement('canvas').getContext('webgl2');
const ok = gl != null && !gl.isContextLost();
<VideoEffects effects={ok ? [whiteNoise({amount: 0.4})] : []} />
Defensive patterns

Strategy: try-catch

Validate before calling

const gl = document.createElement('canvas').getContext('webgl2');
const webglOk = gl != null && gl.createShader(gl.VERTEX_SHADER) != null && !gl.isContextLost();

Type guard

const canCompileShaders = (): boolean => {
  const gl = document.createElement('canvas').getContext('webgl2');
  return gl != null && !gl.isContextLost() && gl.createShader(gl.VERTEX_SHADER) != null;
};

Try / catch

try {
  return <VideoEffects effects={[whiteNoise({amount: 0.4})]} />;
} catch (err) {
  if (err instanceof Error && err.message === 'Failed to create shader') {
    return <Video />; // skip noise when GPU shaders are unavailable
  }
  throw err;
}

Prevention

When it happens

Trigger: createWhiteNoiseState -> createProgram -> compileShader calls gl.createShader(type) and receives null on the first frame the whiteNoise() effect renders.

Common situations: Headless Chromium in CI/Lambda with WebGL2 unavailable or GPU disabled; too many effects holding GL contexts; context lost after tab suspension or driver crash; a software GL backend that caps shader-object allocation.

Related errors


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