Yalantis/uCrop · error · CImgArgumentException

[" cimg_appname "_math_parser] CImg<%s>::%s: Unrecognized %s

Error message

[" cimg_appname "_math_parser] CImg<%s>::%s: Unrecognized %s '%s' in expression '%s'.

What it means

Counterpart to the 'Undefined variable' error in CImg's math parser: when the unknown token looks like an invocation (followed by '(' with a preceding ')'), it is classified as an unrecognized 'function call'; otherwise it is an unrecognized 'item'. The parser throws because it cannot resolve the token to any known function or syntactic element in the expression.

Source

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

        // No known item found, assuming this is an already initialized variable.
        if (cimg::is_varname(variable_name)) { // Valid variable name
          get_variable_pos(variable_name,arg1,arg2);
          arg1 = arg2!=~0U?reserved_label[arg2]:arg1!=~0U?variable_pos[arg1]:~0U;
          if (arg1!=~0U) _cimg_mp_return(arg1);
        }

        // Reached an unknown item -> error.
        c1 = *se1;
        cimg::strellipsize(variable_name,64);
        _cimg_mp_strerr;
        if (is_sth)
          throw CImgArgumentException("[" cimg_appname "_math_parser] "
                                      "CImg<%s>::%s: Undefined variable '%s' in expression '%s'.",
                                      pixel_type(),_cimg_mp_calling_function,
                                      variable_name._data,s0);
        s1 = std::strchr(ss,'(');
        s_op = s1 && c1==')'?"function call":"item";
        throw CImgArgumentException("[" cimg_appname "_math_parser] "
                                    "CImg<%s>::%s: Unrecognized %s '%s' in expression '%s'.",
                                    pixel_type(),_cimg_mp_calling_function,
                                    s_op,variable_name._data,s0);
      }

      // Evaluation procedure.
      double operator()(const double x, const double y, const double z, const double c) {
        mem[_cimg_mp_slot_x] = x; mem[_cimg_mp_slot_y] = y; mem[_cimg_mp_slot_z] = z; mem[_cimg_mp_slot_c] = c;
        for (p_code = code; p_code<p_code_end; ++p_code) {
          opcode._data = p_code->_data;
          const ulongT target = opcode[1];
          mem[target] = _cimg_mp_defunc(*this);
        }
        return *result;
      }

      // Evaluation procedure (return output values in vector 'output').
      template<typename t>

View on GitHub (pinned to f788b534b4)

Solutions

  1. Verify the function name exists in your CImg version's math-function list; fix typos.
  2. Update the vendored CImg.h if the expression uses functions added in a newer version.
  3. Rewrite unsupported functions using available parser primitives/macros.
  4. Remove or correct stray characters that make the token unparseable.
  5. Test the expression in a small standalone CImg program before embedding it.

Example fix

// before
img.fill(sqtr(x)); // unrecognized function call
// after
img.fill(sqrt(x)); // existing parser function
Defensive patterns

Strategy: validation

Validate before calling

Set<String> knownFns = Set.of("sin","cos","sqrt","abs","min","max"); // per your CImg version
for (String fn : extractCalledFunctions(expression))
    if (!knownFns.contains(fn)) throw new IllegalArgumentException("unknown function: " + fn);

Try / catch

try {
    img.fill(expression);
} catch (CImgInstantiationException e) {
    if (e.getMessage().contains("Unrecognized")) {
        // check whether 'function call' or 'item' in message, correct token
    }
    throw e;
}

Prevention

When it happens

Trigger: Evaluating an expression containing a call to a function name that does not exist in the parser's function table (typo or removed/renamed builtin), or an unparseable token sequence such as stray punctuation.

Common situations: Calling functions from newer CImg versions on an older vendored copy (e.g. the JNI-bundled CImg.h in ucrop); typos like sqtr(x) instead of sqrt(x); locale-copied expressions with mangled characters.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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