Yalantis/uCrop · error · CImgArgumentException
"[" cimg_appname "_math_parser] CImg<%s>: Function 'draw()':
Error message
"[" 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."
What it means
CImg's math-parser 'draw()' opcode validates the target image vector against the user-supplied geometry (w,h,d,s). When the vector's element count (sizD) is smaller than w*h*d*s, it cannot be reshaped into the requested geometry, so CImgArgumentException is thrown to prevent out-of-bounds access.
Source
Thrown at ucrop/src/main/jni/CImg.h:30167
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);
const CImg<doubleT> S(ptrs,dx,dy,dz,dc,true);
const float opacity = (float)_mp_arg(17);
if (mp.opcode[18]!=~0U) { // Opacity mask specifiedView on GitHub (pinned to f788b534b4)
Solutions
- Increase the target vector so it contains at least w*h*d*s values, or
- Reduce the specified geometry (w,h,d,s) so its product does not exceed the vector size sizD
- Verify sizes at runtime with .size() before invoking draw() in the expression
Example fix
// before draw(ind,vec_target,4,4,1,1,...); // target has 8 values // after draw(ind,vec_target,2,4,1,1,...); // geometry matches 8-value vector
Defensive patterns
Strategy: validation
Validate before calling
if (target.size() < (unsigned long)w*h*d*s) { /* fix geometry or vector */ } Prevention
- Compute geometry from the vector's actual size instead of hard-coding
- Assert vector.size() >= w*h*d*s before building draw() expressions
- Centralize dimension constants shared between vector creation and draw() calls
When it happens
Trigger: Calling draw(...) in a CImg math expression/formula where the target vector has fewer values than the product of the specified dimensions w*h*d*s (e.g. draw with target geometry 4x4 but a 8-element vector).
Common situations: Hand-written math_parser expressions with mismatched dimension arguments; dynamically computed sizes that under-run the declared geometry; porting scripts between image sizes without updating geometry constants.
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
- "[" cimg_appname "_math_parser] CImg<%s>: Function 'draw()':
- "[" cimg_appname "_math_parser] CImg<%s>: Function 'draw()':
- [" cimg_appname "_math_parser] CImg<%s>::%s: %s%s %s%s (of t
- [" cimg_appname "_math_parser] CImg<%s>::%s: %s%s Specified
- "[" cimg_appname "_math_parser] CImg<%s>: Function '%s()': S
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/9b63e37eee630f2d.
Report an issue: GitHub.