Yalantis/uCrop · error · CImgArgumentException

"[" cimg_appname "_math_parser] CImg<

Error message

"[" cimg_appname "_math_parser] CImg<%s>: Function 'draw()': Invalid specified target vector geometry (%d,%d,%d,%d)."

What it means

The math parser 'draw()' function renders into a target vector interpreted with a specified 4D geometry (w,h,d,s). It first validates that all four dimensions are strictly positive; if any is <= 0, a CImgArgumentException reports the invalid target geometry before checking capacity.

Solutions

  1. Ensure all four target dimensions are > 0 in the expression (e.g. max(1, expr)).
  2. Pass the geometry of the destination vector directly (its actual w,h,d,s) rather than computed values.
  3. Fix argument ordering so dimensions and coordinates are not swapped.
  4. Check upstream computations that produced an empty (0-sized) result before drawing.
  5. Catch CImgArgumentException and report the requested geometry for diagnosis.

Example fix

// before: draw(T, ..., 0, H, D, S)
// after:  draw(T, ..., W, H, D, S)  // W = vector width
Defensive patterns

Strategy: validation

Validate before calling

if (w <= 0 || h <= 0 || d <= 0 || s <= 0)
  throw std::runtime_error("draw() target geometry must be positive");

Try / catch

try { img.evaluate(drawExpr); } catch (const CImgArgumentException& e) { log("draw() bad geometry: " << e.what()); }

Prevention

When it happens

Trigger: draw(...,w,h,d,s,...) in a math expression where one of the geometry arguments (from _mp_arg(9..12) or defaults) evaluates to zero or negative — e.g. a dimension variable computed as 0, or the ~0U sentinel handling leaving w=0 when the caller passed 0 explicitly.

Common situations: Computing target geometry from empty/failed upstream results (a size-0 vector); typos swapping arguments so a coordinate lands in a dimension slot; uninitialized math variables defaulting to 0.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/e8edc043b3fd241d. Report an issue: GitHub.

Appendix: source

Thrown at ucrop/src/main/jni/CImg.h:30163

      }

      static double mp_vector_draw(_cimg_math_parser& mp) {
        double *const ptrd = &_mp_arg(1) + 1;
        const double *const ptrs = &_mp_arg(7) + 1;
        const unsigned int
          sizD = (unsigned int)mp.opcode[2],
          sizS = (unsigned int)mp.opcode[8];
        const int
          w = (int)_mp_arg(3), h = (int)_mp_arg(4), d = (int)_mp_arg(5), s = (int)_mp_arg(6),
          x = (int)_mp_arg(9), y = (int)_mp_arg(10), z = (int)_mp_arg(11), c = (int)_mp_arg(12);
        int dx = (int)mp.opcode[13], dy = (int)mp.opcode[14], dz = (int)mp.opcode[15], dc = (int)mp.opcode[16];
        dx = (unsigned int)dx==~0U?w:(int)_mp_arg(13);
        dy = (unsigned int)dy==~0U?h:(int)_mp_arg(14);
        dz = (unsigned int)dz==~0U?d:(int)_mp_arg(15);
        dc = (unsigned int)dc==~0U?s:(int)_mp_arg(16);

        if (w<=0 || h<=0 || d<=0 || s<=0)
          throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'draw()': "
                                      "Invalid specified target vector geometry (%d,%d,%d,%d).",
                                      mp.imgin.pixel_type(),w,h,d,s);
        if (sizD<(ulongT)w*h*d*s)
          throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'draw()': "
                                      "Target vector (%lu values) and its specified target geometry (%d,%d,%d,%d) "
                                      "(%lu values) do not match.",
                                      mp.imgin.pixel_type(),sizD,w,h,d,s,(ulongT)w*h*d*s);
        if (dx<=0 || dy<=0 || dz<=0 || dc<=0)
          throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'draw()': "
                                      "Invalid specified sprite geometry (%d,%d,%d,%d).",
                                      mp.imgin.pixel_type(),dx,dy,dz,dc);
        if (sizS<(ulongT)dx*dy*dz*dc)
          throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'draw()': "
                                      "Sprite vector (%lu values) and its specified sprite geometry (%d,%d,%d,%d) "
                                      "(%lu values) do not match.",
                                      mp.imgin.pixel_type(),sizS,dx,dy,dz,dc,(ulongT)dx*dy*dz*dc);

        CImg<doubleT> D(ptrd,w,h,d,s,true);

View on GitHub (pinned to f788b534b4)