{"record":{"id":"8643de4836664abd","repo":"remotion-dev/remotion","slug":"failed-to-create-shader-8643de","errorCode":null,"errorMessage":"Failed to create shader","messagePattern":"Failed to create shader","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/effects/src/white-noise.ts","lineNumber":109,"sourceCode":"}\n\nvoid main() {\n\tvec4 color = texture(uSource, vUv);\n\tfloat noise = random(gl_FragCoord.xy);\n\tvec3 unpremultiplied = color.a == 0.0 ? vec3(0.0) : color.rgb / color.a;\n\tvec3 mixed = mix(unpremultiplied, vec3(noise), uAmount);\n\tfragColor = vec4(mixed * color.a, color.a);\n}\n`;\n\nconst compileShader = (\n\tgl: WebGL2RenderingContext,\n\ttype: number,\n\tsource: string,\n): WebGLShader => {\n\tconst shader = gl.createShader(type);\n\tif (!shader) {\n\t\tthrow new Error('Failed to create shader');\n\t}\n\n\tgl.shaderSource(shader, source);\n\tgl.compileShader(shader);\n\n\tif (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n\t\tconst info = gl.getShaderInfoLog(shader) ?? 'Unknown shader compile error';\n\t\tgl.deleteShader(shader);\n\t\tthrow new Error(info);\n\t}\n\n\treturn shader;\n};\n\nconst createProgram = (\n\tgl: WebGL2RenderingContext,\n\tvertexSource: string,\n\tfragmentSource: string,","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/effects/src/white-noise.ts#L91-L127","documentation":"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.","triggerScenarios":"createWhiteNoiseState -> createProgram -> compileShader calls gl.createShader(type) and receives null on the first frame the whiteNoise() effect renders.","commonSituations":"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.","solutions":["Probe WebGL2 availability and context health before applying whiteNoise().","Render headless with Remotion's bundled Chrome and its enabled software-GPU flags; avoid --disable-gpu overrides.","Cut the number of concurrently-mounted WebGL effects to free GL object slots.","Recreate the composition after webglcontextlost so setup runs against a fresh context.","Move rendering to an environment with a functional GPU / updated drivers."],"exampleFix":"// before\nimport {whiteNoise} from '@remotion/effects';\n<VideoEffects effects={[whiteNoise({amount: 0.4})]} />\n\n// after: only attach the effect when WebGL2 is healthy\nconst gl = document.createElement('canvas').getContext('webgl2');\nconst ok = gl != null && !gl.isContextLost();\n<VideoEffects effects={ok ? [whiteNoise({amount: 0.4})] : []} />","handlingStrategy":"try-catch","validationCode":"const gl = document.createElement('canvas').getContext('webgl2');\nconst webglOk = gl != null && gl.createShader(gl.VERTEX_SHADER) != null && !gl.isContextLost();","typeGuard":"const canCompileShaders = (): boolean => {\n  const gl = document.createElement('canvas').getContext('webgl2');\n  return gl != null && !gl.isContextLost() && gl.createShader(gl.VERTEX_SHADER) != null;\n};","tryCatchPattern":"try {\n  return <VideoEffects effects={[whiteNoise({amount: 0.4})]} />;\n} catch (err) {\n  if (err instanceof Error && err.message === 'Failed to create shader') {\n    return <Video />; // skip noise when GPU shaders are unavailable\n  }\n  throw err;\n}","preventionTips":["Verify WebGL2 can allocate a shader object before applying shader-based effects.","Render headless with Remotion's bundled Chrome; do not disable the software GPU.","Cap the number of concurrent WebGL effects.","Re-create the context on webglcontextlost."],"tags":["webgl","gpu","shader","rendering","headless"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}