{"record":{"id":"1f4997667b472c6e","repo":"remotion-dev/remotion","slug":"failed-to-create-webgl-texture-1f4997","errorCode":null,"errorMessage":"Failed to create WebGL texture","messagePattern":"Failed to create WebGL texture","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/effects/src/light-trail/light-trail-runtime.ts","lineNumber":88,"sourceCode":"};\n\nconst createProgram = (\n\tgl: WebGL2RenderingContext,\n\tvertexSource: string,\n\tfragmentSource: string,\n): WebGLProgram => {\n\tconst vs = compileShader(gl, gl.VERTEX_SHADER, vertexSource);\n\tconst fs = compileShader(gl, gl.FRAGMENT_SHADER, fragmentSource);\n\tconst program = linkProgram(gl, vs, fs);\n\tgl.deleteShader(vs);\n\tgl.deleteShader(fs);\n\treturn program;\n};\n\nconst createRgbaTexture = (gl: WebGL2RenderingContext): WebGLTexture => {\n\tconst texture = gl.createTexture();\n\tif (!texture) {\n\t\tthrow new Error('Failed to create WebGL texture');\n\t}\n\n\tgl.bindTexture(gl.TEXTURE_2D, texture);\n\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);\n\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);\n\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n\tgl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n\tgl.bindTexture(gl.TEXTURE_2D, null);\n\treturn texture;\n};\n\nexport const setupLightTrail = (target: HTMLCanvasElement): LightTrailState => {\n\tconst gl = target.getContext('webgl2', {\n\t\tpremultipliedAlpha: true,\n\t\talpha: true,\n\t\tpreserveDrawingBuffer: true,\n\t});\n\tif (!gl) {","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/effects/src/light-trail/light-trail-runtime.ts#L70-L106","documentation":"Thrown when `gl.createTexture()` returns null during lightTrail setup. The texture is the source sampling surface. Per-spec failure means context loss, OUT_OF_MEMORY, or texture-handle exhaustion — the most common real cause is leaking textures by not cleaning up effect state across many setups.","triggerScenarios":"Repeatedly calling `setupLightTrail` without matching `cleanupLightTrail`; a frame loop that re-allocates state every render; context loss mid-setup.","commonSituations":"Forgetting cleanup in a hot-reload loop in Studio; long render sessions on Lambda that accumulate textures; many effects stacked and each setup leaks one texture.","solutions":["Always pair `setupLightTrail` with `cleanupLightTrail` (GL resources are not GC'd reliably).","Cache the setup keyed by params (the effect already does this — make sure you are not bypassing it).","On `webglcontextlost`, call cleanup and rebuild on restore.","Cap concurrent active WebGL effects per worker."],"exampleFix":"// before\nuseEffect(() => { setupLightTrail(canvas); }, []); // no cleanup\n\n// after\nuseEffect(() => {\n  const state = setupLightTrail(canvas);\n  return () => cleanupLightTrail(state);\n}, []);","handlingStrategy":"fallback","validationCode":"const texturePoolHealthy = (gl: WebGL2RenderingContext): boolean => {\n  const probe = gl.createTexture();\n  if (probe) { gl.deleteTexture(probe); return true; }\n  return false;\n};","typeGuard":null,"tryCatchPattern":"useEffect(() => {\n  let state: LightTrailState | null = null;\n  try { state = setupLightTrail(canvas); } catch (e) { state = null; }\n  return () => { if (state) cleanupLightTrail(state); };\n}, []);","preventionTips":["Always call cleanupLightTrail in useEffect teardown.","Cache setup by params; never re-allocate per frame.","Recover on context loss/restore."],"tags":["webgl","light-trail","effects","gpu","resource-leak"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}