Yalantis/uCrop · error · CImgArgumentException

"[" cimg_appname "_math_parser] CImg<%s>: Function 'draw()':

Error message

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

What it means

The math-parser 'draw()' opcode requires positive sprite (source) dimensions. When any of dx,dy,dz,dc passed to draw() is <= 0, the sprite geometry is meaningless and CImg throws CImgArgumentException before attempting to wrap the sprite vector.

Source

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

          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);
        const CImg<doubleT> S(ptrs,dx,dy,dz,dc,true);
        const float opacity = (float)_mp_arg(17);

        if (mp.opcode[18]!=~0U) { // Opacity mask specified
          const ulongT sizM = mp.opcode[19];
          if (sizM<(ulongT)dx*dy*dz)
            throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'draw()': "
                                        "Mask vector (%lu values) and specified sprite geometry (%u,%u,%u,%u) "
                                        "(%lu values) do not match.",

View on GitHub (pinned to f788b534b4)

Solutions

  1. Ensure all sprite geometry arguments dx,dy,dz,dc are >= 1
  2. Check the expressions/variables feeding dx,dy,dz,dc for values that collapse to 0
  3. Guard the draw() call so it only runs when the sprite image is non-empty

Example fix

// before
draw(ind,src,w0,h0,0,1,...); // dc = 0
// after
draw(ind,src,w0,h0,d0,c0,...); // all dims >= 1
Defensive patterns

Strategy: validation

Validate before calling

if (dx <= 0 || dy <= 0 || dz <= 0 || dc <= 0) { /* skip or fix geometry */ }

Prevention

When it happens

Trigger: Calling draw(...) where the sprite geometry arguments dx, dy, dz or dc evaluate to zero or negative (e.g. variables resolved at runtime to 0).

Common situations: Dimension expressions computed from image properties that return 0 for empty images; off-by-one or wrong-variable arguments in formulas; user input supplying 0 for a channel count.

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/9971441c512cbced. Report an issue: GitHub.