Yalantis/uCrop · error · CImgArgumentException
"[" cimg_appname "_math_parser] CImg<%s>: Function 'draw()':
Error message
"[" cimg_appname "_math_parser] CImg<%s>: Function 'draw()': Sprite vector (%lu values) and its specified geometry (%u,%u,%u,%u) (%lu values) do not match."
What it means
The math parser's draw() function interprets a sprite vector as an image with geometry (dx,dy,dz,dc) specified via arguments/defaults from the target image. This error is thrown when the sprite vector holds fewer values (sizS) than the requested geometry requires, i.e. the geometry would read past the vector's data.
Source
Thrown at ucrop/src/main/jni/CImg.h:27215
unsigned int ind = (unsigned int)mp.opcode[3];
if (ind!=~0U) {
if (!mp.imglist.width()) return cimg::type<double>::nan();
ind = (unsigned int)cimg::mod((int)_mp_arg(3),mp.imglist.width());
}
CImg<T> &img = ind==~0U?mp.imgout:mp.imglist[ind];
unsigned int
dx = (unsigned int)mp.opcode[8],
dy = (unsigned int)mp.opcode[9],
dz = (unsigned int)mp.opcode[10],
dc = (unsigned int)mp.opcode[11];
dx = dx==~0U?img._width:(unsigned int)_mp_arg(8);
dy = dy==~0U?img._height:(unsigned int)_mp_arg(9);
dz = dz==~0U?img._depth:(unsigned int)_mp_arg(10);
dc = dc==~0U?img._spectrum:(unsigned int)_mp_arg(11);
const ulongT sizS = mp.opcode[2];
if (sizS<(ulongT)dx*dy*dz*dc)
throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'draw()': "
"Sprite vector (%lu values) and its specified 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> S(&_mp_arg(1) + 1,dx,dy,dz,dc,true);
const float opacity = (float)_mp_arg(12);
if (img._data) {
if (mp.opcode[13]!=~0U) { // Opacity mask specified
const ulongT sizM = mp.opcode[14];
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(13) + 1,dx,dy,dz,(unsigned int)(sizM/(dx*dy*dz)),true);
img.draw_image(x,y,z,c,S,M,opacity,(float)_mp_arg(15));
} else img.draw_image(x,y,z,c,S,opacity);
}View on GitHub (pinned to f788b534b4)
Solutions
- Enlarge the sprite vector so it contains at least dx*dy*dz*dc values (e.g. via input/insert of the right length).
- Reduce the geometry arguments (dx,dy,dz,dc) to fit within the vector size.
- Use default geometry derived from the sprite vector itself instead of explicit dimensions.
- Verify vector length with a size check before draw().
Example fix
// before: geometry larger than vector (10 values vs 2x2x1x3=12 needed) draw(#0,vec[10],2,2,1,3,...) // after: provide full 12-value vector draw(#0,vec12,2,2,1,3,...)
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the sprite vector can fill the requested geometry before draw()
function checkSprite(sizS, dx, dy, dz, dc) { const need = dx * dy * dz * dc; if (sizS < need) throw new Error('sprite has ' + sizS + ' values, geometry needs ' + need); } Type guard
function spriteFitsGeometry(sizS, dx, dy, dz, dc) { return sizS >= dx * dy * dz * dc; } Try / catch
try { evalMath(drawExpr); } catch (e) { if (String(e).includes("Function 'draw()'") && String(e).includes('do not match')) { console.error('sprite/geometry mismatch:', e.message); } else throw e; } Prevention
- Derive geometry from the vector length (or vice versa) from one source of truth
- Recompute defaults after resizing the target image
- Assert vector sizes at build time in generated expressions
When it happens
Trigger: Calling draw() with explicit or default dx,dy,dz,dc whose product dx*dy*dz*dc exceeds the sprite vector's length (mp.opcode[2] values).
Common situations: Hand-editing geometry arguments in a draw() expression; target image resized so defaults (from img dimensions) no longer fit the sprite vector; copying a draw() call between expressions with different vector sizes.
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>::%s: %s: Invalid types i
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Type of first a
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Type of first a
- [" cimg_appname "_math_parser] CImg<%s>::%s: %s: Type of fir
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/21982b39da0b82ef.
Report an issue: GitHub.