parallax/jsPDF · error · Error
Must supply either a local or global palette.
Error message
Must supply either a local or global palette.
What it means
Thrown by GifWriter.addFrame when neither a local palette (opts.palette) nor a global palette (gopts.palette passed to the GifWriter constructor) is available. Every frame needs a color table to decode its indices; addFrame falls back from local to global and errors if both are absent.
Source
Thrown at src/libs/omggif.js:161
// 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);
// Compute the min_code_size (power of 2), destroying num_colors.
var min_code_size = 0;
while ((num_colors >>= 1)) ++min_code_size;
num_colors = 1 << min_code_size; // Now we can easily get it back.
var delay = opts.delay === undefined ? 0 : opts.delay;
// From the spec:
// 0 - No disposal specified. The decoder is
// not required to take any action.
// 1 - Do not dispose. The graphic is to be left
// in place.
// 2 - Restore to background color. The area used by the
// graphic must be restored to the background color.
// 3 - Restore to previous. The decoder is required toView on GitHub (pinned to a3930ce03a)
Solutions
- Supply gopts.palette when creating the GifWriter for a shared global palette.
- Or supply opts.palette on every addFrame call for per-frame palettes.
- Centralize palette resolution so every frame path provides one.
Example fix
// before
var gw = new GifWriter(buf, w, h, {});
gw.addFrame(0, 0, w, h, pixels); // no palette anywhere
// after
var gw = new GifWriter(buf, w, h, { palette: globalPal });
gw.addFrame(0, 0, w, h, pixels); Defensive patterns
Strategy: validation
Validate before calling
function ensurePalette(gopts, frameOpts){ return frameOpts.palette || gopts.palette || null; }
var pal = ensurePalette(gopts, opts); if (pal) gw.addFrame(x, y, w, h, pixels, pal ? { palette: pal } : opts); Type guard
function hasPaletteAvailable(gopts, opts){ return !!(opts && opts.palette) || !!(gopts && gopts.palette); } Try / catch
try { gw.addFrame(x, y, w, h, pixels, opts); } catch (e) { if (/local or global palette/.test(e.message)) { opts.palette = defaultPalette; gw.addFrame(x, y, w, h, pixels, opts); } else throw e; } Prevention
- Always set a global palette on GifWriter
- Provide per-frame palettes when global is absent
When it happens
Trigger: Constructing GifWriter without gopts.palette and then calling addFrame without opts.palette; passing opts.palette = null explicitly; clearing the global palette reference.
Common situations: Single-frame GIFs where the author expected the palette to be inferred (omggif does not infer); animation code that only sets palettes per-frame on some frames.
Related errors
- Transparent color index.
- Invalid code/color length, must be power of 2 and 2 .. 256.
- Background index out of range.
- Background index explicitly passed as 0.
- Loop count invalid.
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/971fb97308f7e59e.
Report an issue: GitHub.