Yalantis/uCrop · error · CImgArgumentException
[cimg_appname_math_parser] CImg<%s>::%s: %s: Invalid assignm
Error message
[cimg_appname_math_parser] CImg<%s>::%s: %s: Invalid assignment of %sconst variable '%s'%s, in expression '%s'.
What it means
CImg allows variables to be declared const (e.g. 'const x = ...'). Assigning a new value to a variable that is already const, or to a const scalar slot, is rejected by the expression compiler with this error.
Source
Thrown at ucrop/src/main/jni/CImg.h:18700
if (is_const) arg1 = arg3;
else {
arg1 = is_sth || is_comp_scalar(arg3)?arg3:scalar1(mp_copy,arg3);
memtype[arg1] = -1;
}
}
if (arg2!=~0U) reserved_label[arg2] = arg1;
else {
if (variable_def._width>=variable_pos._width) variable_pos.resize(-200,1,1,1,0);
variable_pos[variable_def._width] = arg1;
variable_name.move_to(variable_def);
}
} else { // Variable already exists -> assign a new value
if (is_const || is_const_scalar(arg1)) {
cimg::strellipsize(variable_name,64);
_cimg_mp_strerr;
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Invalid assignment of %sconst variable '%s'%s, "
"in expression '%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
is_const_scalar(arg1)?"":"non-",
variable_name._data,
!is_const_scalar(arg1) && is_const?" as a const variable":"",
s0);
}
_cimg_mp_check_type(arg3,2,is_vector(arg1)?3:1,size(arg1));
if (is_vector(arg1)) { // Vector
if (is_vector(arg3)) // From vector
CImg<ulongT>::vector((ulongT)mp_vector_copy,arg1,arg3,(ulongT)size(arg1)).
move_to(code);
else // From scalar
CImg<ulongT>::vector((ulongT)mp_vector_init,arg1,1,(ulongT)size(arg1),arg3).
move_to(code);
} else // Scalar
CImg<ulongT>::vector((ulongT)mp_copy,arg1,arg3).move_to(code);View on GitHub (pinned to f788b534b4)
Solutions
- Remove the 'const' keyword from the original declaration
- Use a different variable name for the new value
- Restructure the expression so const variables are write-once
Example fix
// before const x = 3; x = x + 1; // after x = 3; x = x + 1; // or keep const and use y = x + 1
Defensive patterns
Strategy: validation
Validate before calling
// Track const declarations in your expression strings
function findConstReassign(expr) {
const consts = [...expr.matchAll(/const\s+([A-Za-z_]\w*)\s*=/g)].map(m => m[1]);
return consts.filter(name =>
new RegExp(`(?<!const\\s)\\b${name}\\s*(=[^=]|\\+=|-=|\\*=|/=)`).test(expr)
);
}
Try / catch
try {
img.evaluate(expr);
} catch (e) {
if (/Invalid assignment of .*const variable/.test(String(e))) {
// remove const or rename the assignment target
} else throw e;
}
Prevention
- Treat const variables as write-once
- Use distinct names for derived values instead of reassigning consts
- Search expressions for 'const' declarations before adding assignments
When it happens
Trigger: Using assignment ('=', '+=', etc.) on a variable that was previously defined with 'const', or assigning to a memory slot holding a constant scalar (is_const_scalar(arg1)).
Common situations: Reusing a const variable name as a loop accumulator, mixing const declarations with later reassignments in long expressions.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Invalid %slvalu
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Too much specif
- [cimg_appname_math_parser] CImg<%s>::%s: %s: %s name specifi
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Array brackets
- [cimg_appname_math_parser] CImg<%s>::%s: Out-of-bounds refer
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/42aea72e00ed7ba2.
Report an issue: GitHub.