Yalantis/uCrop · error · CImgArgumentException

[" cimg_appname "_math_parser] CImg<%s>::%s: %s%s %s%s (of t

Error message

[" cimg_appname "_math_parser] CImg<%s>::%s: %s%s %s%s (of type '%s' and value %g) is not a%s constant, in expression '%s'.

What it means

This is a stricter constant check in the CImg math parser: the argument must not only be a compile-time constant but must satisfy a mode-specific constraint - mode 0/1 require an integer value, mode 2 requires a non-negative integer, and mode 3 requires a strictly positive integer. If mem[arg] fails the check, the error reports the argument's type and actual value %g so the offending value is visible.

Source

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

        _cimg_mp_check_type(arg,n_arg,1,0);
        if (!is_const_scalar(arg)) {
          const char *const s_arg = s_argth(n_arg);
          char *s0;
          _cimg_mp_strerr;
          throw CImgArgumentException("[" cimg_appname "_math_parser] "
                                      "CImg<%s>::%s: %s%s %s%s (of type '%s') is not a constant, "
                                      "in expression '%s'.",
                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?":":"",
                                      s_arg,*s_arg?" argument":" Argument",s_type(arg)._data,s0);
        }
        const double val = mem[arg];

        if (!((!mode || (double)(int)mem[arg]==mem[arg]) &&
              (mode<2 || mem[arg]>=(mode==3)))) {
          const char *const s_arg = s_argth(n_arg);
          char *s0;
          _cimg_mp_strerr;
          throw CImgArgumentException("[" cimg_appname "_math_parser] "
                                      "CImg<%s>::%s: %s%s %s%s (of type '%s' and value %g) is not a%s constant, "
                                      "in expression '%s'.",
                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?":":"",
                                      s_arg,*s_arg?" argument":" Argument",s_type(arg)._data,val,
                                      !mode?"":mode==1?"n integer":
                                      mode==2?" positive integer":" strictly positive integer",s0);
        }
      }

      // Check if an image index is a constant value.
      void check_const_index(const unsigned int arg,
                             char *const ss, char *const se, const char saved_char) {
        if (arg!=~0U && !is_const_scalar(arg)) {
          char *s0;
          _cimg_mp_strerr;
          throw CImgArgumentException("[" cimg_appname "_math_parser] "
                                      "CImg<%s>::%s: %s%s Specified image index is not a constant, "
                                      "in expression '%s'.",

View on GitHub (pinned to f788b534b4)

Solutions

  1. Pass a whole-number literal (e.g. 3 not 3.0 computed) in the required position
  2. Round the value in C++ before embedding it: use cimg::round() or (int) cast, then format into the expression string
  3. Ensure sign constraints: use an absolute value or max(1,...) when a strictly positive integer is needed
  4. Read the error's reported value and mode suffix ('integer', 'positive integer', 'strictly positive integer') to see which constraint was violated

Example fix

// before
img.fill("mirror(2.5)"); // not an integer constant
// after
img.fill("mirror(3)"); // integer constant
// or compute in C++:
char expr[64];
snprintf(expr, sizeof(expr), "mirror(%d)", (int)cimg::round(v,1));
img.fill(expr);
Defensive patterns

Strategy: validation

Validate before calling

// C++: clamp/round values to the required integer class before embedding
int check_positive_int(double v) {
  int i = (int)std::llround(v);
  if (i < 1) throw std::invalid_argument("need strictly positive integer");
  return i;
}
char buf[64];
std::snprintf(buf, sizeof(buf), "mirror(%d)", check_positive_int(user_value));

Type guard

bool is_positive_integer(double v) { return v == (double)(long long)v && v > 0; }

Try / catch

try {
  img.fill(expr.c_str());
} catch (const cimg_library::CImgArgumentException& e) {
  std::cerr << "Integer-constant constraint violated: " << e.what() << std::endl;
}

Prevention

When it happens

Trigger: Calling a CImg math-expression function whose argument must be an integer constant (e.g. axis, dimension, count, or index) with a fractional value like 2.5, a negative value where positivity is required, or zero where a strictly positive value is required.

Common situations: Computing sizes or counts with floating-point arithmetic and passing the result directly (3.0000001 from a division); using negative offsets; hard-coding 0 for a 1-based index; rounding errors from float math making an 'integer' value non-integral.

Related errors


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