remotion-dev/remotion · error · Error
Failed to acquire 2D context for hue effect. The canvas may
Error message
Failed to acquire 2D context for hue effect. The canvas may have been assigned a different context type.
What it means
Thrown in the apply() step of the hue effect when target.getContext('2d') returns null. Unlike the WebGL helper-canvas errors, this 'target' is the working canvas the Remotion engine hands to 2D-backend effects, and the message explicitly suggests the canvas may already hold a different (incompatible) context type. A canvas can only host one context family; once it has been given a 'webgl'/'webgl2'/'bitmaprenderer' context, subsequent getContext('2d') calls return null.
Source
Thrown at packages/effects/src/hue.ts:47
const validateHueParams = (params: HueParams): void => {
assertEffectParamsObject(params, 'Hue');
assertOptionalFiniteNumber(params.degrees, 'degrees');
};
export const hue = createEffect<HueParams, null>({
type: 'dev.remotion.effects.hue',
label: 'hue()',
documentationLink: 'https://www.remotion.dev/docs/effects/hue',
backend: '2d',
calculateKey: (params) => {
const r = resolve(params);
return `hue-${r.degrees}`;
},
setup: () => null,
apply: ({source, target, width, height, params}) => {
const ctx = target.getContext('2d');
if (!ctx) {
throw new Error(
'Failed to acquire 2D context for hue effect. The canvas may have been assigned a different context type.',
);
}
const r = resolve(params);
ctx.clearRect(0, 0, width, height);
ctx.filter = `hue-rotate(${r.degrees}deg)`;
ctx.drawImage(source, 0, 0, width, height);
ctx.filter = 'none';
},
cleanup: () => undefined,
schema: hueSchema,
validateParams: validateHueParams,
});
View on GitHub (pinned to 78fe4bb3fd)
Solutions
- Give the hue effect a canvas that has never been used with a non-2D context — use a fresh canvas per effect.
- If building a custom pipeline, never call getContext('webgl...') and getContext('2d') on the same canvas.
- Use the Remotion engine's effect scheduler as-is, which allocates canvases per backend.
- Reorder so all 2D-backend effects share one canvas and all WebGL effects share another.
Example fix
// before: same canvas reused across backends
const ctx2d = canvas.getContext('2d'); // for hue
const gl = canvas.getContext('webgl2'); // earlier, on same canvas
// after: one canvas per backend
const canvas2d = document.createElement('canvas');
const canvasGl = document.createElement('canvas'); Defensive patterns
Strategy: validation
Validate before calling
// Ensure the canvas passed to the hue effect has never been acquired as a non-2D context.
function canvasHas2dAvailable(canvas: HTMLCanvasElement): boolean {
// Note: calling getContext('2d') itself claims the context, so only call this on a throwaway probe,
// or trust the engine to hand each effect a fresh canvas per backend.
return canvas.dataset.contextType === undefined || canvas.dataset.contextType === '2d';
} Try / catch
try {
hue({ degrees: 90 }).apply({ source, target, width, height, params: { degrees: 90 } });
} catch (e) {
if (e instanceof Error && /Failed to acquire 2D context for hue effect/.test(e.message)) {
// target canvas had an incompatible context; allocate a fresh 2D canvas
} else throw e;
} Prevention
- Never call getContext('webgl...') and getContext('2d') on the same canvas — a canvas keeps only one context family.
- Let the Remotion engine allocate one canvas per effect backend rather than pooling a single canvas yourself.
- If you build a custom pipeline, group effects by backend so each canvas stays single-context-family.
When it happens
Trigger: The hue effect receiving a target canvas that the engine (or another effect) previously acquired as WebGL or bitmaprenderer; an engine misconfiguration that reuses a canvas across incompatible effect backends.
Common situations: Custom integrations that pass the same canvas to both WebGL2-backend and 2D-backend effects; a fork of the Remotion engine that pools canvases naively; mixing hue() after a WebGL2 effect on the same canvas in a hand-rolled pipeline.
Related errors
- Failed to acquire 2D context for invert effect. The canvas m
- Failed to acquire 2D context for color parsing
- Failed to acquire 2D context for color parsing
- "hueShift" must be >= 0, but got ${hueShift}
- "hueShift" must be <= 360, but got ${hueShift}
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/940b3c4ae98456cf.
Report an issue: GitHub.