{"record":{"id":"60b04fb699be0556","repo":"parallax/jsPDF","slug":"disposal-out-of-range","errorCode":null,"errorMessage":"Disposal out of range.","messagePattern":"Disposal out of range\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/libs/omggif.js","lineNumber":188,"sourceCode":"    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\n    //           restore the area overwritten by the graphic with\n    //           what was there prior to rendering the graphic.\n    //  4-7 -    To be defined.\n    // NOTE(deanm): Dispose background doesn't really work, apparently most\n    // browsers ignore the background palette index and clear to transparency.\n    var disposal = opts.disposal === undefined ? 0 : opts.disposal;\n    if (disposal < 0 || disposal > 3)\n      // 4-7 is reserved.\n      throw new Error(\"Disposal out of range.\");\n\n    var use_transparency = false;\n    var transparent_index = 0;\n    if (opts.transparent !== undefined && opts.transparent !== null) {\n      use_transparency = true;\n      transparent_index = opts.transparent;\n      if (transparent_index < 0 || transparent_index >= num_colors)\n        throw new Error(\"Transparent color index.\");\n    }\n\n    if (disposal !== 0 || use_transparency || delay !== 0) {\n      // - Graphics Control Extension\n      buf[p++] = 0x21;\n      buf[p++] = 0xf9; // Extension / Label.\n      buf[p++] = 4; // Byte size.\n\n      buf[p++] = (disposal << 2) | (use_transparency === true ? 1 : 0);\n      buf[p++] = delay & 0xff;","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/libs/omggif.js#L170-L206","documentation":"Thrown by GifWriter.addFrame when opts.disposal is outside 0..3. GIF disposal methods are 0 (unspecified), 1 (do not dispose), 2 (restore to background), 3 (restore to previous); values 4-7 are reserved by the spec and rejected.","triggerScenarios":"Passing { disposal: 4 } or higher; passing a negative disposal; deriving disposal from an enum whose numbering differs from GIF spec values.","commonSituations":"Using a generic animation disposal enum (some libraries use 1-4 instead of 0-3); defaulting to an out-of-range sentinel.","solutions":["Map your disposal enum to GIF values 0..3 before addFrame.","Omit opts.disposal to use the default 0.","Validate disposal is an integer in 0..3."],"exampleFix":"// before\ngw.addFrame(x, y, w, h, pixels, { disposal: animEnumRestore }); // animEnumRestore === 4\n// after\nvar gifDisposal = Math.max(0, Math.min(3, animEnumRestore - 1));\ngw.addFrame(x, y, w, h, pixels, { disposal: gifDisposal });","handlingStrategy":"validation","validationCode":"function normDisposal(d){ d = d == null ? 0 : Math.floor(d); return d < 0 ? 0 : d > 3 ? 3 : d; }\ngw.addFrame(x, y, w, h, pixels, { disposal: normDisposal(opts.disposal) });","typeGuard":"function isValidDisposal(v){ return v == null || (Number.isInteger(v) && v >= 0 && v <= 3); }","tryCatchPattern":"try { gw.addFrame(x, y, w, h, pixels, opts); } catch (e) { if (/Disposal out of range/.test(e.message)) { opts.disposal = 0; gw.addFrame(x, y, w, h, pixels, opts); } else throw e; }","preventionTips":["Map external disposal enums to GIF 0..3","Omit disposal to use the default 0"],"tags":["gif","omggif","image","animation","validation","disposal"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}