{"record":{"id":"46ff14bd67fdba23","repo":"remotion-dev/remotion","slug":"webgl-context-was-lost-during-canvas-effect-render","errorCode":null,"errorMessage":"WebGL context was lost during canvas effect rendering. This typically happens in headless or memory-constrained environments (e.g. Remotion Lambda). Try reducing concurrency or increasing the Lambda function memory.","messagePattern":"WebGL context was lost during canvas effect rendering\\. This typically happens in headless or memory-constrained environments \\(e\\.g\\. Remotion Lambda\\)\\. Try reducing concurrency or increasing the Lambda function memory\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/effects/canvas-pool.ts","lineNumber":41,"sourceCode":"\t}\n\n\tpublic getPair(backend: Backend): CanvasPair {\n\t\tconst existing = this.pairs.get(backend);\n\t\tif (existing) {\n\t\t\treturn existing;\n\t\t}\n\n\t\tconst pair = [\n\t\t\tthis.allocateCanvas(backend),\n\t\t\tthis.allocateCanvas(backend),\n\t\t] as const;\n\t\tthis.pairs.set(backend, pair);\n\t\treturn pair;\n\t}\n\n\tpublic assertContextNotLost(canvas: HTMLCanvasElement): void {\n\t\tif (this.lostContexts.has(canvas)) {\n\t\t\tthrow new Error(\n\t\t\t\t'WebGL context was lost during canvas effect rendering. ' +\n\t\t\t\t\t'This typically happens in headless or memory-constrained environments (e.g. Remotion Lambda). ' +\n\t\t\t\t\t'Try reducing concurrency or increasing the Lambda function memory.',\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate allocateCanvas(backend: Backend): HTMLCanvasElement {\n\t\tconst canvas = document.createElement('canvas');\n\t\tcanvas.width = this.width;\n\t\tcanvas.height = this.height;\n\n\t\tswitch (backend) {\n\t\t\tcase '2d': {\n\t\t\t\tconst ctx = canvas.getContext('2d', {\n\t\t\t\t\tcolorSpace: 'srgb',\n\t\t\t\t});\n\t\t\t\tif (!ctx) {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/core/src/effects/canvas-pool.ts#L23-L59","documentation":"The canvas effect pool tracks WebGL contexts that have fired 'webglcontextlost' (a browser signal that the GPU resources were reclaimed, common under memory pressure or in headless mode). Before each effect pass, assertContextNotLost checks the canvas and throws if its context was lost, so rendering fails fast rather than silently producing blank frames.","triggerScenarios":"Running many WebGL-based effects concurrently on Remotion Lambda or in a low-memory headless Chrome, where the GPU process reclaims contexts. Also triggered by driver crashes, too many simultaneous WebGL contexts, or insufficient Lambda memory.","commonSituations":"High concurrency Lambda renders with WebGL-heavy effect chains; local headless rendering with limited GPU memory; stacking many canvas/webgl2 effects in one composition.","solutions":["Reduce render concurrency (fewer parallel frames / Chrome tabs) on Lambda or locally.","Increase Lambda function memory (which also raises GPU/CPU).","Reduce the number of simultaneous WebGL effects or lower canvas resolution."],"exampleFix":"// before (CLI)\nremotion render MyComp out.mp4 --concurrency=16\n\n// after\nremotion render MyComp out.mp4 --concurrency=4","handlingStrategy":"fallback","validationCode":"// before render: size concurrency and memory to the workload\nconst concurrency = Math.min(4, safeConcurrency);\nconst memoryMB = 2048; // or higher on Lambda","typeGuard":null,"tryCatchPattern":"try {\n  await renderMedia(...);\n} catch (e) {\n  if (String(e?.message).includes('WebGL context was lost')) {\n    // reduce concurrency and retry once\n  } else throw e;\n}","preventionTips":["Right-size Lambda memory and concurrency before running WebGL-heavy renders.","Limit simultaneous WebGL effects per composition.","Monitor for webglcontextlost events during local dev to catch pressure early."],"tags":["effects","webgl","rendering","lambda","environment","memory"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}