{"record":{"id":"971fb97308f7e59e","repo":"parallax/jsPDF","slug":"must-supply-either-a-local-or-global-palette","errorCode":null,"errorMessage":"Must supply either a local or global palette.","messagePattern":"Must supply either a local or global palette\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/libs/omggif.js","lineNumber":161,"sourceCode":"    // canvas width/height, I imagine?\n    if (x < 0 || y < 0 || x > 65535 || y > 65535)\n      throw new Error(\"x/y invalid.\");\n\n    if (w <= 0 || h <= 0 || w > 65535 || h > 65535)\n      throw new Error(\"Width/Height invalid.\");\n\n    if (indexed_pixels.length < w * h)\n      throw new Error(\"Not enough pixels for the frame size.\");\n\n    var using_local_palette = true;\n    var palette = opts.palette;\n    if (palette === undefined || palette === null) {\n      using_local_palette = false;\n      palette = global_palette;\n    }\n\n    if (palette === undefined || palette === null)\n      throw new Error(\"Must supply either a local or global palette.\");\n\n    var num_colors = check_palette_and_num_colors(palette);\n\n    // Compute the min_code_size (power of 2), destroying num_colors.\n    var min_code_size = 0;\n    while ((num_colors >>= 1)) ++min_code_size;\n    num_colors = 1 << min_code_size; // Now we can easily get it back.\n\n    var delay = opts.delay === undefined ? 0 : opts.delay;\n\n    // From the spec:\n    //     0 -   No disposal specified. The decoder is\n    //           not required to take any action.\n    //     1 -   Do not dispose. The graphic is to be left\n    //           in place.\n    //     2 -   Restore to background color. The area used by the\n    //           graphic must be restored to the background color.\n    //     3 -   Restore to previous. The decoder is required to","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/libs/omggif.js#L143-L179","documentation":"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.","triggerScenarios":"Constructing GifWriter without gopts.palette and then calling addFrame without opts.palette; passing opts.palette = null explicitly; clearing the global palette reference.","commonSituations":"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.","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."],"exampleFix":"// before\nvar gw = new GifWriter(buf, w, h, {});\ngw.addFrame(0, 0, w, h, pixels); // no palette anywhere\n// after\nvar gw = new GifWriter(buf, w, h, { palette: globalPal });\ngw.addFrame(0, 0, w, h, pixels);","handlingStrategy":"validation","validationCode":"function ensurePalette(gopts, frameOpts){ return frameOpts.palette || gopts.palette || null; }\nvar pal = ensurePalette(gopts, opts); if (pal) gw.addFrame(x, y, w, h, pixels, pal ? { palette: pal } : opts);","typeGuard":"function hasPaletteAvailable(gopts, opts){ return !!(opts && opts.palette) || !!(gopts && gopts.palette); }","tryCatchPattern":"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; }","preventionTips":["Always set a global palette on GifWriter","Provide per-frame palettes when global is absent"],"tags":["gif","omggif","image","animation","palette","validation"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}