diff --git a/packages/core/src/audioAutomation.test.ts b/packages/core/src/audioAutomation.test.ts index 7b9af2c747..b73ef35cd9 100644 --- a/packages/core/src/audioAutomation.test.ts +++ b/packages/core/src/audioAutomation.test.ts @@ -341,6 +341,17 @@ describe("sampling", () => { expect(shapeProgress(0.05, { viaX: 0.05, viaY: 0.95 })).toBeCloseTo(0.95, 6); }); + it("never returns NaN for a via point dragged past the segment edge", () => { + // A via point pulled out to (5, -3) clamps to (0.999, 0.001) — exactly on the + // steady region's edge, where `edge - viaX` is 0 and the conic's weight used + // to divide out to Infinity, then NaN a few steps later. NaN reaching + // setValueCurveAtTime silences the node for the rest of the render. + for (const x of [0, 0.1, 0.25, 0.5, 0.75, 0.9, 1]) { + const y = shapeProgress(x, { viaX: 5, viaY: -3 }); + expect(Number.isFinite(y)).toBe(true); + } + }); + it("never flattens a bend that is pulled harder", () => { // The regression. Holding a bend's depth inside the steady region by clamping // its coordinates one at a time snapped the curve flat mid-drag: near the ends diff --git a/packages/core/src/audioAutomation.ts b/packages/core/src/audioAutomation.ts index a2cdef1c92..a47edf13fe 100644 --- a/packages/core/src/audioAutomation.ts +++ b/packages/core/src/audioAutomation.ts @@ -405,10 +405,15 @@ function viaConic(viaX: number, viaY: number): { cx: number; cy: number; w: numb const dy = viaY - 0.5; const edge = 0.999; // Per axis, `C` stays inside when the weight is at least the pull divided by the - // room left in the pull's own direction. + // room left in the pull's own direction. A via point clamped to `edge` itself + // leaves zero room — `edge - viaX` is exactly 0 — which would divide out to + // Infinity and carry NaN into every downstream sample. Capped rather than left + // unbounded: past this weight the arc already reads as touching the via point, + // so the cap costs no visible reach. + const MAX_WEIGHT = 1e6; const needX = dx > 0 ? dx / (edge - viaX) : dx < 0 ? -dx / (viaX - (1 - edge)) : 0; const needY = dy > 0 ? dy / (edge - viaY) : dy < 0 ? -dy / (viaY - (1 - edge)) : 0; - const w = Math.max(1, needX, needY); + const w = Math.min(MAX_WEIGHT, Math.max(1, needX, needY)); return { cx: viaX + dx / w, cy: viaY + dy / w, w }; } @@ -434,7 +439,7 @@ function shapeVia(x: number, viaX: number, viaY: number): number { const t = conicParam(a, b, x); const rest = 1 - t; const denominator = rest * rest + 2 * w * t * rest + t * t; - if (denominator <= 0) return x; + if (!(denominator > 0)) return x; return (2 * w * cy * t * rest + t * t) / denominator; }