Yalantis/uCrop · error · CImgArgumentException
[" cimg_appname "_math_parser] CImg<%s>::%s: %s: Type of fir
Error message
[" cimg_appname "_math_parser] CImg<%s>::%s: %s: Type of first arguments ('%s') does not match with third argument 'nb_channelsX=%u', in expression '%s'. What it means
The second divisibility check in the same multi-channel operator: after validating the first argument against nb_channelsX, CImg checks that the second argument's size p2 is divisible by nb_channelsP (arg4). If not, it throws this error naming the second argument's type and the P channel count. Note the message text in the corpus header is mislabeled ('first arguments'/'nb_channelsX') while the actual throw site reports the second argument and 'nb_channelsP'.
Source
Thrown at ucrop/src/main/jni/CImg.h:22520
_cimg_mp_check_const_scalar(arg3,3,3);
_cimg_mp_check_const_scalar(arg4,4,3);
_cimg_mp_check_type(arg5,5,1,0);
p1 = size(arg1);
p2 = size(arg2);
arg3 = (unsigned int)mem[arg3];
arg4 = (unsigned int)mem[arg4];
if (p1%arg3) {
_cimg_mp_strerr;
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Type of first arguments ('%s') "
"does not match with third argument 'nb_channelsX=%u', "
"in expression '%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
s_type(arg1)._data,arg3,s0);
}
if (p2%arg4) {
_cimg_mp_strerr;
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Type of second arguments ('%s') "
"does not match with fourth argument 'nb_channelsP=%u', "
"in expression '%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
s_type(arg2)._data,arg4,s0);
}
pos = vector(p1*arg4);
CImg<ulongT>::vector((ulongT)mp_map,pos,arg1,arg2,p1,p2,arg3,arg4,arg5).move_to(code);
return_comp = true;
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"mul(",4)) { // Matrix multiplication
_cimg_mp_op("Function 'mul()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss4,s1,depth1,0,block_flags);
s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;
arg2 = compile(s1,s2,depth1,0,block_flags);View on GitHub (pinned to f788b534b4)
Solutions
- Ensure the second vector's length is an exact multiple of nb_channelsP
- Set nb_channelsP to match the actual layout of the second argument (1/3/4)
- Re-pad or re-generate the second buffer so its size aligns with the channel count
- Check both divisibility conditions in code before invoking the expression to get clearer diagnostics
Example fix
// before
img.fill("op(dataX, [p0..p6], 3, 3)"); // 7 not divisible by 3
// after
img.fill("op(dataX, [p0..p8], 3, 3)"); // 9 divisible by 3 Defensive patterns
Strategy: validation
Validate before calling
void checkChannelsP(double[] p, int nbChannelsP) {
if (p.length % nbChannelsP != 0)
throw new IllegalArgumentException("Input P size " + p.length + " not a multiple of nb_channelsP=" + nbChannelsP);
} Try / catch
try { img.fill(expr); } catch (CImgArgumentException e) { if (e.getMessage().contains("nb_channelsP")) { /* fix secondary vector layout and retry */ } throw e; } Prevention
- Check both inputs' divisibility (X and P) before invoking the expression
- Use one shared channel-layout constant for all vectors in the operation
- Re-pad secondary buffers when channel counts change upstream
When it happens
Trigger: Calling the same multi-channel function with a second (P, e.g. palette/secondary) vector whose length is not a multiple of nb_channelsP, e.g. second vector of 7 values with nb_channelsP=3.
Common situations: Mismatched channel layouts between the two inputs (one RGB, one RGBA); stale constants after changing one input's channel count; concatenating buffers of different channel widths.
Related errors
- [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: Input vecto
- [" cimg_appname "_math_parser] CImg<%s>::%s: %s%s %s%s (of t
- [" cimg_appname "_math_parser] CImg<%s>: Function '%s()': Sp
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/e038408ed4225f06.
Report an issue: GitHub.