{"record":{"id":"ecf50be7fc248ec4","repo":"remotion-dev/remotion","slug":"failed-to-create-levels-shader","errorCode":null,"errorMessage":"Failed to create levels shader","messagePattern":"Failed to create levels shader","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/effects/src/levels.ts","lineNumber":161,"sourceCode":"\tvec3 normalized = clamp(\n\t\t(color - vec3(uBlackPoint)) / (uWhitePoint - uBlackPoint),\n\t\t0.0,\n\t\t1.0\n\t);\n\tvec3 corrected = pow(normalized, vec3(1.0 / uGamma));\n\n\tfragColor = vec4(corrected * 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 levels 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(`Levels shader compile failed: ${log ?? '(no log)'}`);\n\t}\n\n\treturn shader;\n};\n\nconst createProgram = (gl: WebGL2RenderingContext): WebGLProgram => {\n\tconst vertexShader = compileShader(gl, gl.VERTEX_SHADER, VERTEX_SHADER);\n\tconst fragmentShader = compileShader(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);\n\tconst program = gl.createProgram();\n\tif (!program) {","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/effects/src/levels.ts#L143-L179","documentation":"Thrown by `compileShader()` inside the levels effect when `gl.createShader()` returns `null`. The WebGL2 spec returns null only on context loss, an invalid enum, or resource/GPU exhaustion — the effect cannot build its shader program and bails before compiling.","triggerScenarios":"The WebGL2 context was lost (e.g. tab backgrounded, GPU driver reset), too many simultaneous WebGL contexts are open (browsers cap around 16), the GPU is unavailable in a headless/CI environment, or video memory is exhausted.","commonSituations":"Rendering many compositions concurrently on the same machine; running Remotion Lambda/headless Chrome with `--disable-gpu` or swiftshader; a long-running Studio tab that lost its context after suspend; opening dozens of effect previews at once.","solutions":["Reduce the number of live WebGL2 contexts — close other Studio tabs or lower concurrency (`--concurrency`).","Ensure the renderer has a working GPU: avoid `--disable-gpu` in headless Chrome; use a GPU-enabled Chromium or swiftshader build that still exposes WebGL2.","Listen for `webglcontextlost` and tear down/recreate the effect, or retry the render after the context is restored.","If running in CI/Lambda, confirm the Chrome binary and GPU flags match Remotion's supported headless setup."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"function glReady(gl: WebGL2RenderingContext | null): boolean {\n  if (!gl) return false;\n  // Probe a throwaway shader allocation cheaply.\n  const probe = gl.createShader(gl.VERTEX_SHADER);\n  if (!probe) return false;\n  gl.deleteShader(probe);\n  return gl.isContextLost() === false;\n}","typeGuard":"const hasWebGL2 = (): boolean => {\n  const c = document.createElement('canvas');\n  return !!c.getContext('webgl2');\n};","tryCatchPattern":"try {\n  levels({...})(...);\n} catch (err) {\n  if (/Failed to create levels shader/.test(String(err))) {\n    // context loss / no GPU: skip effect or schedule a retry after restore\n    console.warn('levels() unavailable, falling back to no-op', err);\n  } else {\n    throw err;\n  }\n}","preventionTips":["Keep concurrent WebGL2 contexts well below the ~16 browser cap.","In headless rendering, use a GPU-backed Chrome (no --disable-gpu) or a WebGL2-capable swiftshader.","Add a `webglcontextlost` listener to tear down effects and retry on restore."],"tags":["levels","webgl2","gpu","context-loss","render-env","resource-exhaustion"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}