heygen-com/hyperframes · error · RangeError

Curve LUT size must be at least 2

Error message

Curve LUT size must be at least 2

What it means

validateCurvePoints() rejects a LUT `size` that is not an integer or is less than 2. Size is the number of samples the curve is compiled into (the Float32Array length). A non-integer or sub-2 size makes sampling mathematically invalid (index/(size-1) divides by zero or produces fractional indices).

Source

Thrown at packages/core/src/colorGradingCurves.ts:75

    const before = valueAt(slopes, index - 1);
    const after = valueAt(slopes, index);
    if (before === 0 || after === 0 || Math.sign(before) !== Math.sign(after)) {
      result[index] = 0;
      continue;
    }
    const beforeSpan = valueAt(spans, index - 1);
    const afterSpan = valueAt(spans, index);
    const beforeWeight = 2 * afterSpan + beforeSpan;
    const afterWeight = afterSpan + 2 * beforeSpan;
    result[index] = (beforeWeight + afterWeight) / (beforeWeight / before + afterWeight / after);
  }
  return result;
}

function validateCurvePoints(points: readonly HfColorCurvePoint[], size: number): void {
  if (points.length < 2) throw new RangeError("A color curve requires at least two points");
  if (!Number.isInteger(size) || size < 2) {
    throw new RangeError("Curve LUT size must be at least 2");
  }
  let previousInput = Number.NEGATIVE_INFINITY;
  for (const [input, output] of points) {
    if (!Number.isFinite(input) || !Number.isFinite(output)) {
      throw new TypeError("Color curve points must be finite");
    }
    if (input <= previousInput) {
      throw new RangeError("Color curve inputs must be strictly increasing");
    }
    previousInput = input;
  }
}

function validateOutputRange(
  points: readonly HfColorCurvePoint[],
  outputMin: number,
  outputMax: number,
): void {

View on GitHub (pinned to c2996c8626)

Solutions

  1. Omit the size argument to use the default HF_COLOR_CURVE_LUT_SIZE (1024).
  2. If supplying a custom size, ensure it is an integer >= 2 (and typically a power of two for GPU textures).

Example fix

// before
const lut = compileHfColorCurve(pts, 1); // size < 2

// after
const lut = compileHfColorCurve(pts); // default 1024
// or an explicit valid size
const lut = compileHfColorCurve(pts, 256);
Defensive patterns

Strategy: validation

Validate before calling

function validLutSize(n: number): boolean { return Number.isInteger(n) && n >= 2; }
const size = opts.size && validLutSize(opts.size) ? opts.size : HF_COLOR_CURVE_LUT_SIZE;

Type guard

function isValidLutSize(n: unknown): n is number {
  return typeof n === "number" && Number.isInteger(n) && n >= 2;
}

Try / catch

try { compileHfColorCurve(pts, size); }
catch (err) { if (/LUT size/.test(String(err))) { compileHfColorCurve(pts); } else throw err; }

Prevention

When it happens

Trigger: Calling compileHfColorCurve(points, 1), compileHfColorCurve(points, 0), compileHfColorCurve(points, 1.5), compileHfColorCurve(points, NaN), or compileHfColorCurve(points, -4) as the second argument. The default HF_COLOR_CURVE_LUT_SIZE (1024) avoids this.

Common situations: Passing a custom small size for testing; computing size from a variable that went NaN or got truncated; misusing the API by passing the number of points as the second arg.

Related errors


AI-assisted analysis of heygen-com/hyperframes@c2996c8626 (2026-08-12). Data as JSON: /api/errors/1acd585c5d804999. Report an issue: GitHub.