Yalantis/uCrop · error · CImgArgumentException
[cimg_appname_math_parser] CImg<%s>::%s: %s: Type of first a
Error message
[cimg_appname_math_parser] CImg<%s>::%s: %s: Type of first argument ('%s') does not match with second argument 'nb_colsA=%u', in expression '%s'. What it means
Matrix/vector reshaping functions in the parser (e.g. building a square matrix from a flat vector) accept either an implicit square shape (when nb_colsA is 0/omitted) or an explicit column count. When an explicit nb_colsA is given, the flat first argument's size p1 must equal p3*p2; if p1 is not divisible by nb_colsA, CImg throws this error naming the first argument's type (s_type(arg1)) and the column count.
Source
Thrown at ucrop/src/main/jni/CImg.h:22229
}
if (arg2!=~0U) {
_cimg_mp_check_const_scalar(arg2,2,3);
arg2 = (unsigned int)mem[arg2];
}
_cimg_mp_check_type(arg3,3,1,0);
_cimg_mp_check_type(arg4,4,1,0);
if (is_vector(arg1)) {
p1 = size(arg1);
if (arg2==~0U) { // nb_colsA not specified: assuming square matrix
_cimg_mp_check_matrix_square(arg1,1);
p2 = p3 = (unsigned int)cimg::round(std::sqrt((float)p1));
} else {
p2 = arg2;
p3 = p1/p2;
if (p3*p2!=p1) {
_cimg_mp_strerr;
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Type of first argument ('%s') "
"does not match with second argument 'nb_colsA=%u', "
"in expression '%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
s_type(arg1)._data,p2,s0);
}
}
pos = vector(p1);
CImg<ulongT>::vector((ulongT)mp_matrix_invert,pos,arg1,p2,p3,arg3,arg4).move_to(code);
return_comp = true;
_cimg_mp_return(pos);
}
if (is_const_scalar(arg1)) _cimg_mp_const_scalar(1/mem[arg1]);
_cimg_mp_scalar2(mp_div,1,arg1);
}
if (*ss1=='s') { // Family of 'is_?()' functions
View on GitHub (pinned to f788b534b4)
Solutions
- Make the first argument's size an exact multiple of nb_colsA (fix the data or the column count)
- Omit/zero the second argument to let CImg infer a square matrix when the data is square
- Verify the flattening order (row-major vs column-major) matches what the function expects
- Compute nb_colsA programmatically from data.size() instead of hard-coding it
Example fix
// before
img.fill("mat([1,2,3,4,5,6,7,8,9,10],3)"); // 10 not divisible by 3
// after
img.fill("mat([1,2,3,4,5,6,7,8,9],3)"); // 9 divisible by 3 Defensive patterns
Strategy: validation
Validate before calling
void checkMatrixShape(double[] flat, int nbCols) {
if (nbCols > 0 && flat.length % nbCols != 0)
throw new IllegalArgumentException("Flat matrix size " + flat.length + " incompatible with nb_colsA=" + nbCols);
} Try / catch
try { img.fill(expr); } catch (CImgArgumentException e) { if (e.getMessage().contains("does not match with second argument 'nb_colsA'")) { /* recompute columns or fix data length */ } throw e; } Prevention
- Derive nb_colsA from the data length instead of hard-coding
- Pass 0/omit the second argument to get implicit square shape
- Confirm flattening order when serializing matrices
When it happens
Trigger: Calling a matrix-construction expression function with an explicit second argument nb_colsA that doesn't divide the length of the first vector argument, e.g. a 10-value vector with nb_colsA=3; also passing a scalar where a vector shape is required.
Common situations: Computing matrix dimensions by hand and miscounting elements; loading matrices saved with a different row-major/column-major layout; off-by-one truncation when serializing the matrix data.
Related errors
- [" cimg_appname "_math_parser] CImg<%s>::%s: %s%s %s%s (of t
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Type of first a
- [" cimg_appname "_math_parser] CImg<%s>::%s: %s: Type of fir
- [" cimg_appname "_math_parser] CImg<%s>::%s: %s: Input vecto
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Types of first
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/6967ea4be1cdf59c.
Report an issue: GitHub.