diff --git a/extensions/src/doodlebot/LineFollowing.ts b/extensions/src/doodlebot/LineFollowing.ts index 17d3a74d8..640c2819d 100644 --- a/extensions/src/doodlebot/LineFollowing.ts +++ b/extensions/src/doodlebot/LineFollowing.ts @@ -545,9 +545,18 @@ export function followLine(previousLine: Point[], pixels: Point[], next: Point[] if (test) { x3 = spline.xs[0]; } else { - x3 = start; + x3 = spline.xs[0]; + } + const splineValue = spline.at(x3); + if (typeof splineValue === 'undefined') { + // Handle the error case - either return early or use a default value + return { + motorCommands: [], + bezierPoints: [], + line: [] + }; } - const point3 = { x: spline.at(x3), y: x3 } + const point3 = { x: splineValue, y: x3 }; // Find the x offset to correct const reference1 = [spline.at(spline.xs[0]), 0] // First point should be very close to 0