Yalantis/uCrop · error · CImgArgumentException
[cimg_appname_math_parser] CImg<%s>::%s: %s: Invalid specifi
Error message
[cimg_appname_math_parser] CImg<%s>::%s: %s: Invalid specified variable name '%s', in expression '%s'.
What it means
When parsing a variable declaration/assignment, the parser validates the identifier with cimg::is_varname(). If the token (e.g. starting with a digit, containing illegal characters, or being an empty/parenthesized fragment) is not a valid variable name, the error is thrown with the elided (max 64 chars) name.
Source
Thrown at ucrop/src/main/jni/CImg.h:23053
pos = vector(arg1);
CImg<ulongT>::vector((ulongT)mp_vector_rand,pos,arg1,arg2,arg3,arg4,p2,arg5).move_to(code);
return_comp = true;
_cimg_mp_return(pos);
}
if (!std::strncmp(ss,"ref(",4)) { // Variable declaration
_cimg_mp_op("Function 'ref()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
if (s1>=se1 || !*s1) compile(s1,s1,depth1,0,block_flags); // Will throw missing argument error
arg3 = compile(ss4,s1++,depth1,p_ref,block_flags|32);
*se1 = 0;
if (!cimg::is_varname(s1)) { // Invalid variable name
variable_name.assign(s1,(unsigned int)(se1 + 1 - s1)).back() = 0;
cimg::strellipsize(variable_name,64);
*se1 = ')';
_cimg_mp_strerr;
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: Invalid specified variable name '%s', "
"in expression '%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
variable_name._data,s0);
}
get_variable_pos(s1,arg1,arg2);
if (arg2!=~0U) reserved_label[arg2] = arg3;
else if (arg1!=~0U) variable_pos[arg1] = arg3;
else { // New variable
if (variable_def._width>=variable_pos._width) variable_pos.resize(-200,1,1,1,0);
variable_pos[variable_def._width] = arg3;
CImg<char>::string(s1).move_to(variable_def);
}
if (is_vector(arg3))
set_reserved_vector(arg3); // Prevent from being used in further optimization
else if (is_comp_scalar(arg3)) memtype[arg3] = -1;
*se1 = ')';
_cimg_mp_return(arg3);View on GitHub (pinned to f788b534b4)
Solutions
- Rename the variable so it starts with a letter/underscore and contains only alphanumerics/underscores
- Print or inspect the expression string; a macro or string concatenation may be corrupting the name
- Ensure the assignment target is non-empty (check for missing variable before '=')
- Quote or restructure generated expressions so illegal characters do not leak into identifiers
Example fix
// before 1st_val = 3; // after first_val = 3;
Defensive patterns
Strategy: validation
Validate before calling
const isValidVarname = s => /^[A-Za-z_]\w*$/.test(s);
isValidVarname(name) || error('invalid variable name: ' + name); Try / catch
try { run(expr) } catch (CImgArgumentException &e) { log(e.what()); } Prevention
- Start identifiers with a letter or underscore
- Avoid dashes, digits-first names and special characters
- Sanitize generated expression strings before evaluation
When it happens
Trigger: Assigning to an invalid identifier inside a math expression, e.g. '1abc = 5', 'my-var = 3', 'x$ = 2', or an empty name produced by a malformed expression like '(=)'.
Common situations: Typos in custom G'MIC commands, macro expansion inserting illegal characters into names, generated expressions from string concatenation producing malformed identifiers, or localization/encoding issues in variable names.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Invalid loop va
- [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: Invalid assignm
- [cimg_appname_math_parser] CImg<%s>::%s: %s: Invalid %slvalu
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/9106227c38fbaaa5.
Report an issue: GitHub.