{"record":{"id":"e72cfef71161e560","repo":"gohugoio/hugo","slug":"error-creating-webpanimencoder-n","errorCode":null,"errorMessage":"Error creating WebPAnimEncoder\\n","messagePattern":"Error creating WebPAnimEncoder\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/warpc/genwebp/webp.c","lineNumber":211,"sourceCode":"    if (!ok)\n    {\n        WebPMemoryWriterClear(&wrt);\n        return NULL;\n    }\n    *output_size = wrt.size;\n    return wrt.mem;\n}\n\nstatic uint8_t *encodeNRGBAAnimated(WebPConfig *config, InputParams params, const uint8_t *all_frames_data, size_t *output_size)\n{\n    WebPAnimEncoderOptions anim_options;\n    WebPAnimEncoderOptionsInit(&anim_options);\n    anim_options.anim_params.loop_count = params.loopCount;\n\n    WebPAnimEncoder *enc = WebPAnimEncoderNew(params.width, params.height, &anim_options);\n    if (enc == NULL)\n    {\n        fprintf(stderr, \"Error creating WebPAnimEncoder\\n\");\n        return NULL;\n    }\n\n    int timestamp = 0;\n    size_t frame_rgba_size = (size_t)params.stride * params.height;\n\n    for (int i = 0; i < params.frameCount; i++)\n    {\n        WebPPicture pic;\n        if (!WebPPictureInit(&pic))\n        {\n            fprintf(stderr, \"WebPPictureInit failed\\n\");\n            WebPAnimEncoderDelete(enc);\n            return NULL;\n        }\n        pic.use_argb = 1;\n        pic.width = params.width;\n        pic.height = params.height;","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/internal/warpc/genwebp/webp.c#L193-L229","documentation":"Printed by genwebp's encodeNRGBAAnimated (webp.c:211) when WebPAnimEncoderNew returns NULL. The animated encoder allocation fails for invalid canvas dimensions (over WebP's 16383 cap, or non-positive), or when libwebp cannot allocate the internal animation state. The function returns NULL and the Go host sees 'Error encoding NRGBA to WebP'.","triggerScenarios":"Calling the animated path with params.width or params.height that exceed WebP limits or are <= 0, with an extremely high frameCount that exhausts memory during encoder construction, or under overall process memory pressure.","commonSituations":"Decoding a large animated source (GIF/animated WebP) whose canvas exceeds 16383px, decoding a GIF with hundreds of frames on a memory-constrained worker, or passing zero/negative dimensions because the params struct was not populated.","solutions":["Validate params.width and params.height are in [1, 16383] before entering the animated encode path; downscale or reject otherwise.","Validate params.frameCount matches the actual number of frames supplied and is reasonable (< a few hundred) for the available memory.","If animating large canvases, raise the worker's memory limit or reduce frame resolution.","Prefer skipping the animated WebP output and falling back to a static resize for inputs that overflow the limit.","Log the params struct on the Go side at call time to correlate with this stderr line."],"exampleFix":"// before: animated encode attempted on a 20000px-canvas GIF\nencodeWebpAnimated(frames, 20000, 8000, durations)\n\n// after: reject oversized canvas and fall back\nif w > 16383 || h > 16383 {\n    return fmt.Errorf(\"canvas %dx%d exceeds WebP limit; skipping animated WebP\", w, h)\n}\nencodeWebpAnimated(frames, w, h, durations)","handlingStrategy":"validation","validationCode":"func validateAnimParams(w, h, frameCount int) error {\n    const max = 16383\n    if w <= 0 || h <= 0 || w > max || h > max {\n        return fmt.Errorf(\"canvas %dx%d out of range [1,%d]\", w, h, max)\n    }\n    if frameCount <= 0 { return fmt.Errorf(\"frameCount %d must be > 0\", frameCount) }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reject or downscale canvases larger than 16383px on either edge.","Cap frameCount to what the worker's memory can hold.","For oversized inputs, fall back to a static encode instead of animated.","Log width/height/frameCount on the Go side to correlate with this stderr line."],"tags":["webp","animation","encoding","dimensions","oom"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}