{"record":{"id":"3c882f78e8f3ca37","repo":"remotion-dev/remotion","slug":"failed-to-create-webgl-shader-3c882f","errorCode":null,"errorMessage":"Failed to create WebGL shader","messagePattern":"Failed to create WebGL shader","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/effects/src/noise.ts","lineNumber":148,"sourceCode":"\t\treturn;\n\t}\n\n\tfloat noise = random(gl_FragCoord.xy) - 0.5;\n\tvec3 rgb = texColor.rgb / alpha;\n\tvec3 noiseLayer = uPremultiply ? rgb * noise : vec3(noise);\n\trgb = clamp(rgb + noiseLayer * uAmount, 0.0, 1.0);\n\tfragColor = vec4(rgb * alpha, alpha);\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 WebGL shader');\n\t}\n\n\tgl.shaderSource(shader, source);\n\tgl.compileShader(shader);\n\tif (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n\t\tconst log = gl.getShaderInfoLog(shader);\n\t\tgl.deleteShader(shader);\n\t\tthrow new Error(`Noise shader compile failed: ${log ?? '(no log)'}`);\n\t}\n\n\treturn shader;\n};\n\nconst linkProgram = (\n\tgl: WebGL2RenderingContext,\n\tvs: WebGLShader,\n\tfs: WebGLShader,\n): WebGLProgram => {","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/effects/src/noise.ts#L130-L166","documentation":"Thrown by compileShader (packages/effects/src/noise.ts:148) when gl.createShader(type) returns null while compiling the noise effect's vertex or fragment shader. A null shader object indicates a lost WebGL2 context or exhausted GL object budget; the shader source itself is not yet involved at this line.","triggerScenarios":"setupNoise compiling NOISE_VS/NOISE_FS on a canvas whose WebGL2 context was just lost or whose GPU resources are exhausted; compiling after a prior context-loss event that was not handled.","commonSituations":"GPU process crash mid-render; rendering on a host without usable WebGL2; context lost during a heavy parallel render and never restored.","solutions":["Render on a GPU-capable host / GPU-enabled headless Chrome so createShader can allocate.","Handle 'webglcontextlost' and re-run setup after 'webglcontextrestored' instead of reusing a dead context.","Reduce concurrent WebGL2 effects so the shader-object budget is not exhausted."],"exampleFix":"// before\nconst vs = compileShader(gl, gl.VERTEX_SHADER, NOISE_VS); // createShader() returned null\n\n// after: verify the context is alive before compiling\nif (gl.isContextLost()) {\n  throw new Error('WebGL2 context lost before noise setup; retry after restore');\n}","handlingStrategy":"try-catch","validationCode":"function canCompileNoiseShader(): boolean {\n  try {\n    const c = document.createElement('canvas');\n    const gl = c.getContext('webgl2');\n    if (!gl || gl.isContextLost()) return false;\n    const s = gl.createShader(gl.VERTEX_SHADER);\n    const ok = !!s;\n    if (s) gl.deleteShader(s);\n    return ok;\n  } catch {\n    return false;\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  scene.push(noise({amount: 0.2}));\n} catch (err) {\n  if (/Failed to create WebGL shader/.test(String(err?.message))) {\n    // context unhealthy: skip noise and retry render after restore\n  } else throw err;\n}","preventionTips":["Render on a GPU host with WebGL enabled in headless Chrome.","Handle webglcontextlost and re-create the effect after webglcontextrestored.","Avoid reusing a context after a loss without re-running setup."],"tags":["webgl","gpu","noise","effects","shader","context-loss"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}