Yalantis/uCrop · error · CImgArgumentException

[" cimg_appname "_math_parser] CImg<%s>::%s: %s%s %s%s has i

Error message

[" cimg_appname "_math_parser] CImg<%s>::%s: %s%s %s%s has invalid type '%s' (should be %s), in expression '%s'.

What it means

The math parser type-checks arguments/operands against the expected kind (scalar or a vector of expected dimension N). When an operand has the wrong type — e.g. a vector where a scalar is required, or a vector of the wrong dimension — this CImgArgumentException is thrown. The message shows the actual type via s_type(arg) and the expected type string.

Source

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

        bool cond = false;
        if (mode&1) cond|=_is_scalar;
        if (mode&2) cond|=_is_vector;
        if (!cond) {
          const char *s_arg;
          if (*s_op!='F') s_arg = !n_arg?"":n_arg==1?"Left-hand":"Right-hand";
          else s_arg = s_argth(n_arg);
          CImg<charT> sb_type(32);
          if (mode==1) cimg_snprintf(sb_type,sb_type._width,"'scalar'");
          else if (mode==2) {
            if (N) cimg_snprintf(sb_type,sb_type._width,"'vector%u'",N);
            else cimg_snprintf(sb_type,sb_type._width,"'vector'");
          } else {
            if (N) cimg_snprintf(sb_type,sb_type._width,"'scalar' or 'vector%u'",N);
            else cimg_snprintf(sb_type,sb_type._width,"'scalar' or 'vector'");
          }
          char *s0;
          _cimg_mp_strerr;
          throw CImgArgumentException("[" cimg_appname "_math_parser] "
                                      "CImg<%s>::%s: %s%s %s%s has invalid type '%s' (should be %s), "
                                      "in expression '%s'.",
                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?":":"",
                                      s_arg,*s_op=='F'?(*s_arg?" argument":" Argument"):(*s_arg?" operand":" Operand"),
                                      s_type(arg)._data,sb_type._data,s0);
        }
      }

      // Check that imglist are not empty.
      void check_list(char *const ss, char *const se, const char saved_char) {
        if (!imglist) {
          char *s0;
          _cimg_mp_strerr;
          throw CImgArgumentException("[" cimg_appname "_math_parser] "
                                      "CImg<%s>::%s: %s%s Image list cannot be empty, for expression '%s'.",
                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?":":"",s0);
        }
      }

View on GitHub (pinned to f788b534b4)

Solutions

  1. Match the expected type shown in the message: wrap scalars or use [ ] for vectors as needed.
  2. Check the CImg documentation for the exact argument types of the function used.
  3. Correct vector dimension to the required vectorN size.
  4. Test the sub-expression standalone to isolate which operand has the wrong type.

Example fix

// before
img.fill("norm([1,2,3],[4,5])"); // second operand wrong dimension
// after
img.fill("norm([1,2,3],[4,5,6])");
Defensive patterns

Strategy: type-guard

Validate before calling

// Verify operand kind before composing expression
bool scalarOk = std::isfinite(value);

Type guard

bool isScalarArg(const std::string& tok) { return tok.find(',') == std::string::npos && tok.front() != '['; }

Try / catch

try { img.fill(expr); } catch (const cimg_library::CImgArgumentException& e) { /* fix operand type per message */ }

Prevention

When it happens

Trigger: Calling an MP function like 'norm(v)' with a matrix-typed value, or passing a vectorN where scalar/vectorM is required, e.g. 'pand(a,[1,2])' with scalar a expected.

Common situations: Typos in expression variables; misremembering function signatures (vector vs scalar args); wrapping constants in brackets producing unintended vectors.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/7500eb86f41d6ce9. Report an issue: GitHub.