Yalantis/uCrop · error · CImgArgumentException

"[" cimg_appname "_math_parser] CImg<

Error message

"[" 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."

What it means

The math-parser 'draw()' opcode checks that the sprite (source) vector contains at least dx*dy*dz*dc values. If sizS is smaller than the product of the declared sprite geometry, the vector cannot back the requested CImg view, so CImgArgumentException is thrown.

Solutions

  1. Enlarge the sprite vector so it has at least dx*dy*dz*dc values, or
  2. Shrink dx,dy,dz,dc so their product fits within sizS
  3. Print/verify vector size vs geometry product before the call

Example fix

// before
draw(ind,src,10,10,1,3,...); // src has 100 values
// after
draw(ind,src,10,10,1,1,...); // matches 100-value vector
Defensive patterns

Strategy: validation

Validate before calling

if (sprite.size() < (unsigned long)dx*dy*dz*dc) { /* fix sprite or geometry */ }

Prevention

When it happens

Trigger: Calling draw(...) where the sprite vector has fewer elements than the product of the specified sprite dimensions dx*dy*dz*dc.

Common situations: Passing a flat vector with an oversized declared geometry; recomputing geometry after resizing the source without updating the vector; copy-pasted dimension constants from another call site.

Understand the failure class

Background: Tensor shape mismatch errors ("must have shape", "expected shape ... got ..."): when tensor dimensions disagree with what an op or layer was told to expect — this error's family across 6 libraries.

Related errors


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

Appendix: source

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

        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.",
                                        mp.imgin.pixel_type(),sizS,dx,dy,dz,dc,(ulongT)dx*dy*dz*dc);
          const CImg<doubleT> M(&_mp_arg(18) + 1,dx,dy,dz,(unsigned int)(sizM/(dx*dy*dz)),true);
          D.draw_image(x,y,z,c,S,M,opacity,(float)_mp_arg(20));
        } else D.draw_image(x,y,z,c,S,opacity);

View on GitHub (pinned to f788b534b4)