Yalantis/uCrop · error · CImgArgumentException

[" cimg_appname "_math_parser] CImg<%s>::%s: Function '%s()'

Error message

[" cimg_appname "_math_parser] CImg<%s>::%s: Function '%s()': Number of specified arguments (%u) does not match macro declaration (defined for %u argument%s), in expression '%s'.

What it means

Same macro-arity check in CImg's math parser as the sibling error, but for the simple case: the macro is declared for exactly one fixed argument count, and the expression calls it with a different number of arguments. The parser reports the expected count and adds a plural 's' when the expected count is not 1.

Source

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

            if (arg3) { // Macro name matched but number of arguments does not
              CImg<uintT> sig_nargs(arg3);
              arg1 = 0;
              cimglist_for(macro_def,l) if (!std::strcmp(macro_def[l],variable_name))
                sig_nargs[arg1++] = (unsigned int)macro_def[l].back();
              _cimg_mp_strerr;
              cimg::strellipsize(variable_name,64);
              if (sig_nargs._width>1) {
                sig_nargs.sort();
                arg1 = sig_nargs.back();
                --sig_nargs._width;
                throw CImgArgumentException("[" cimg_appname "_math_parser] "
                                            "CImg<%s>::%s: Function '%s()': Number of specified arguments (%u) "
                                            "does not match macro declaration (defined for %s or %u arguments), "
                                            "in expression '%s'.",
                                            pixel_type(),_cimg_mp_calling_function,variable_name._data,
                                            p1,sig_nargs.value_string()._data,arg1,s0);
              } else {
                throw CImgArgumentException("[" cimg_appname "_math_parser] "
                                            "CImg<%s>::%s: Function '%s()': Number of specified arguments (%u) "
                                            "does not match macro declaration (defined for %u argument%s), "
                                            "in expression '%s'.",
                                            pixel_type(),_cimg_mp_calling_function,variable_name._data,
                                            p1,*sig_nargs,*sig_nargs!=1?"s":"",s0);
              }
            }
          }
        } // if (se1==')')

        // Char / string initializer.
        if (*se1=='\'' &&
            ((se1>ss && *ss=='\'') ||
            (se1>ss1 && *ss=='_' && *ss1=='\''))) {
          if (*ss=='_') { _cimg_mp_op("Char initializer"); s1 = ss2; }
          else { _cimg_mp_op("String initializer"); s1 = ss1; }
          arg1 = (unsigned int)(se1 - s1); // Original string length
          if (arg1) {

View on GitHub (pinned to f788b534b4)

Solutions

  1. Read the declared argument count (%u) from the message and adjust the call to pass exactly that many arguments.
  2. Review the macro definition in the expression or CImg source for its signature.
  3. Remove surplus arguments or supply missing ones, separated by commas.
  4. If the macro should accept multiple arities, redefine it with a multi-signature declaration.
  5. Validate generated expressions with a unit test calling each macro once before production use.

Example fix

// before
img.fill(mymacro(x, y)); // mymacro declared for 1 argument
// after
img.fill(mymacro(x));    // exactly the declared 1 argument
Defensive patterns

Strategy: validation

Validate before calling

if (callArgCount != macroArity) throw new IllegalArgumentException("mymacro expects " + macroArity + " argument(s), got " + callArgCount);

Try / catch

try {
    img.fill(expression);
} catch (CImgInstantiationException e) {
    if (e.getMessage().contains("does not match macro declaration")) {
        // parse expected count from message and correct the expression
    }
    throw e;
}

Prevention

When it happens

Trigger: Evaluating a math expression that calls a macro defined for a single arity (sig_nargs width == 1) with the wrong number of arguments, e.g. foo(1,2) when foo is declared for 3 arguments.

Common situations: Typos in fill() expressions; calling built-in or user macros with extra/fewer comma-separated values; expressions ported between CImg versions where a macro's arity changed.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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