{"record":{"id":"71fcb8c8d8f3d1d8","repo":"parallax/jsPDF","slug":"not-enough-pixels-for-the-frame-size","errorCode":null,"errorMessage":"Not enough pixels for the frame size.","messagePattern":"Not enough pixels for the frame size\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/libs/omggif.js","lineNumber":151,"sourceCode":"\n  this.addFrame = function(x, y, w, h, indexed_pixels, opts) {\n    if (ended === true) {\n      --p;\n      ended = false;\n    } // Un-end.\n\n    opts = opts === undefined ? {} : opts;\n\n    // TODO(deanm): Bounds check x, y.  Do they need to be within the virtual\n    // 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","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/parallax/jsPDF/blob/a3930ce03a585a26b2c76d12a0f413ce96f6d1a3/src/libs/omggif.js#L133-L169","documentation":"Thrown by GifWriter.addFrame when indexed_pixels.length < w * h. Each frame must supply at least one palette index per pixel covering its declared dimensions, otherwise the LZW encoder would read out of bounds.","triggerScenarios":"Passing a pixel buffer computed for a smaller region than (w, h); forgetting to include all rows; mismatch between declared frame size and the extracted pixel array length.","commonSituations":"Crop/resize producing fewer pixels than expected; off-by-one in row stride; reusing a previous frame's shorter pixel buffer for a larger frame.","solutions":["Ensure indexed_pixels has exactly w * h entries (one byte per pixel).","Recompute the pixel buffer from the same w, h passed to addFrame.","Add an assertion: if (pixels.length < w*h) before calling."],"exampleFix":"// before\ngw.addFrame(x, y, w, h, partialPixels);\n// after\nvar needed = w * h;\nif (partialPixels.length < needed) throw new Error('frame underrun');\ngw.addFrame(x, y, w, h, partialPixels);","handlingStrategy":"validation","validationCode":"if (indexed_pixels.length >= w * h) gw.addFrame(x, y, w, h, indexed_pixels); else throw new Error('pixel underrun');","typeGuard":"function hasEnoughPixels(px, w, h){ return px && px.length >= w * h; }","tryCatchPattern":"try { gw.addFrame(x, y, w, h, pixels); } catch (e) { if (/Not enough pixels/.test(e.message)) { /* rebuild pixel buffer */ } else throw e; }","preventionTips":["Recompute pixel buffer from the same w,h passed to addFrame","Assert buffer length equals w*h before encoding"],"tags":["gif","omggif","image","animation","validation","buffer-size"],"backgroundTag":null,"analyzedSha":"a3930ce03a585a26b2c76d12a0f413ce96f6d1a3","analyzedAt":"2026-08-13T05:33:39.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}