parallax/jsPDF · error · Error
x/y invalid.
Error message
x/y invalid.
What it means
Thrown by GifWriter.addFrame when the frame's top-left coordinates x or y are negative or exceed 65535. Frame position is stored as unsigned 16-bit fields in the Image Descriptor, so any value outside 0..65535 is rejected. (Note: bounds against the canvas width/height are explicitly a TODO and NOT checked.)
Source
Thrown at src/libs/omggif.js:145
buf[p++] = loop_count & 0xff;
buf[p++] = (loop_count >> 8) & 0xff;
buf[p++] = 0x00; // Terminator.
}
var ended = false;
this.addFrame = function(x, y, w, h, indexed_pixels, opts) {
if (ended === true) {
--p;
ended = false;
} // Un-end.
opts = opts === undefined ? {} : opts;
// TODO(deanm): Bounds check x, y. Do they need to be within the virtual
// canvas width/height, I imagine?
if (x < 0 || y < 0 || x > 65535 || y > 65535)
throw new Error("x/y invalid.");
if (w <= 0 || h <= 0 || w > 65535 || h > 65535)
throw new Error("Width/Height invalid.");
if (indexed_pixels.length < w * h)
throw new Error("Not enough pixels for the frame size.");
var using_local_palette = true;
var palette = opts.palette;
if (palette === undefined || palette === null) {
using_local_palette = false;
palette = global_palette;
}
if (palette === undefined || palette === null)
throw new Error("Must supply either a local or global palette.");
var num_colors = check_palette_and_num_colors(palette);View on GitHub (pinned to a3930ce03a)
Solutions
- Clamp x and y to 0..65535 (typically 0 and within canvas bounds).
- If you need off-canvas content, crop the pixels instead of using negative offsets.
- Validate coordinates are non-negative integers before addFrame.
Example fix
// before gw.addFrame(offsetX, offsetY, w, h, pixels); // after var x = Math.max(0, Math.min(65535, Math.floor(offsetX))); var y = Math.max(0, Math.min(65535, Math.floor(offsetY))); gw.addFrame(x, y, w, h, pixels);
Defensive patterns
Strategy: validation
Validate before calling
function clampCoord(c){ c = Math.floor(c); return c < 0 ? 0 : c > 65535 ? 65535 : c; }
gw.addFrame(clampCoord(x), clampCoord(y), w, h, pixels); Type guard
function isValidFrameCoord(v){ return Number.isInteger(v) && v >= 0 && v <= 65535; } Try / catch
try { gw.addFrame(x, y, w, h, pixels); } catch (e) { if (/x\/y invalid/.test(e.message)) { /* clamp coords */ } else throw e; } Prevention
- Clamp offsets to non-negative integers
- Crop rather than using negative offsets
When it happens
Trigger: Calling addFrame(-5, 0, ...) for an off-canvas frame; passing x/y derived from a centering calc that goes negative; values > 65535 from large-canvas code.
Common situations: Sprite/packing algorithms that allow negative offsets; animation frames positioned relative to a moving origin; unit confusion producing huge coordinates.
Related errors
- Loop count invalid.
- Not enough pixels for the frame size.
- Must supply either a local or global palette.
- Disposal out of range.
- Transparent color index.
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/70380e0fa501cbe9.
Report an issue: GitHub.