Yalantis/uCrop · error · CImgArgumentException

[cimg_appname_math_parser] CImg<%s>::%s: %s: Size of first a

Error message

[cimg_appname_math_parser] CImg<%s>::%s: %s: Size of first argument ('%s') does not match second argument 'nb_cols=%u', in expression '%s'.

What it means

An opcode takes a vector plus a constant scalar nb_cols; the parser computes rows = size(first argument)/nb_cols and requires the division to be exact. A non-zero remainder means the vector size is incompatible with the declared column count, so compilation aborts.

Source

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

              arg1 = compile(ss6,se1,depth1,0,block_flags);
              _cimg_mp_check_matrix_square(arg1,1);
              p1 = (unsigned int)cimg::round(std::sqrt((float)size(arg1)));
              _cimg_mp_scalar2(mp_trace,arg1,p1);
            }

            if (!std::strncmp(ss,"transpose(",10)) { // Matrix transpose
              _cimg_mp_op("Function 'transpose()'");
              s1 = ss + 10; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
              arg1 = compile(ss + 10,s1,depth1,0,block_flags);
              arg2 = compile(++s1,se1,depth1,0,block_flags);
              _cimg_mp_check_type(arg1,1,2,0);
              _cimg_mp_check_const_scalar(arg2,2,3);
              p1 = size(arg1);
              p2 = (unsigned int)mem[arg2];
              p3 = p1/p2;
              if (p2*p3!=p1) {
                _cimg_mp_strerr;
                throw CImgArgumentException("[" cimg_appname "_math_parser] "
                                            "CImg<%s>::%s: %s: Size of first argument ('%s') does not match "
                                            "second argument 'nb_cols=%u', in expression '%s'.",
                                            pixel_type(),_cimg_mp_calling_function,s_op,
                                            s_type(arg1)._data,p2,s0);
              }
              pos = vector(p3*p2);
              CImg<ulongT>::vector((ulongT)mp_transpose,pos,arg1,p2,p3).move_to(code);
              return_comp = true;
              _cimg_mp_return(pos);
            }
            break;

          case 'u' :
            if (!std::strncmp(ss,"ui2f(",5)) { // Special uint->float conversion
              _cimg_mp_op("Function 'ui2f()'");
              arg1 = compile(ss5,se1,depth1,0,block_flags);
              if (is_vector(arg1)) _cimg_mp_vector1_v(mp_ui2f,arg1);
              if (is_const_scalar(arg1))

View on GitHub (pinned to f788b534b4)

Solutions

  1. Change nb_cols to a divisor of size(first argument).
  2. Resize/reshape the vector so its size equals nb_cols*rows.
  3. Compute the column count from the data length rather than hard-coding it.

Example fix

// before: vector size 8
'build(v,3)'
// after
'build(v,4)' // 8/4 = 2 rows
Defensive patterns

Strategy: validation

Validate before calling

if (v.length % nbCols !== 0) throw new Error('Vector size ' + v.length + ' incompatible with nb_cols=' + nbCols);

Try / catch

try { img.eval(expr); } catch (e) { if (/does not match second argument 'nb_cols/.test(e.message)) { /* pick a divisor of v.length */ } else throw e; }

Prevention

When it happens

Trigger: Calling the opcode with a first-argument vector of size n and constant nb_cols=c where c*rows != n, e.g. size 7 with nb_cols=3.

Common situations: Data resized after the expression was written; hard-coded nb_cols not matching a dynamically sized vector; typo in column count.

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/840ef0382818f886. Report an issue: GitHub.