{"record":{"id":"b046da0e265dc8d3","repo":"remotion-dev/remotion","slug":"failed-to-create-white-balance-shader","errorCode":null,"errorMessage":"Failed to create white balance shader","messagePattern":"Failed to create white balance shader","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/effects/src/white-balance.ts","lineNumber":128,"sourceCode":"\t}\n\n\tvec3 unpremultiplied = sourceColor.rgb / alpha;\n\tvec3 linear = srgbToLinear(unpremultiplied);\n\tvec3 balanced = applyWhiteBalanceLinear(linear, uTemperature, uTint);\n\tvec3 corrected = linearToSrgb(balanced);\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 white balance 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(\n\t\t\t`White balance shader compile failed: ${log ?? '(no log)'}`,\n\t\t);\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);","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/effects/src/white-balance.ts#L110-L146","documentation":"Thrown by compileShader() in the white balance effect when gl.createShader(type) returns null. WebGL's createShader returns null on context loss, context destruction, or resource exhaustion. The shader source (VERTEX_SHADER / FRAGMENT_SHADER) is a static library constant incorporating COLOR_SPACE_GLSL and WHITE_BALANCE_GLSL.","triggerScenarios":"Called transitively from setupWhiteBalance() at packages/effects/src/white-balance.ts:194 via createProgram(gl) which calls compileShader for both vertex and fragment shaders. Fires when the GL context is lost or shader object slots are exhausted. User params (temperature, tint) do not cause this.","commonSituations":"WebGL context loss during effect setup; long-running sessions with many white balance effect instances leaking shader objects; constrained GPU environments (mobile, VM, older drivers); GPU process crash mid-setup.","solutions":["Handle 'webglcontextlost'/'webglcontextrestored' events and re-run setupWhiteBalance on a fresh canvas.","Ensure cleanup of old white balance effect states before creating new instances.","Reduce concurrent effect instances to lower shader object pressure.","Update GPU drivers or switch render backends."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"const gl = canvas.getContext('webgl2');\nif (!gl || gl.isContextLost()) {\n  return;\n}\ntry {\n  const state = setupWhiteBalance(canvas);\n} catch (e) {\n  if ((e as Error).message === 'Failed to create white balance shader') {\n    console.warn('White balance shader allocation failed:', (e as Error).message);\n  }\n}","preventionTips":["Handle 'webglcontextlost'/'webglcontextrestored' events.","Ensure white balance effect cleanup runs before creating new instances.","Limit concurrent effect instances."],"tags":["webgl","gpu","shader","resource-exhaustion","white-balance-effect"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}