Yalantis/uCrop · error · CImgArgumentException
[" cimg_appname "_math_parser] CImg<
Error message
[" cimg_appname "_math_parser] CImg<%s>::%s: %s: First argument cannot be a linked reference, in expression '%s'.
What it means
The merge() function in the CImg math parser requires its first argument to be an assignable vector variable, not a linked reference. If compiling the first argument yields a reference (non-zero *ref), e.g. an indirection or a view of another vector, the parser throws because merge would mutate storage it does not own.
Solutions
- Pass a plain vector variable (created via 'vector(...)' or a numeric variable) as first argument to merge()
- Assign the referenced data to a new variable first, then merge that variable
- Rewrite the expression to merge into the actual underlying variable
Example fix
// before merge(I[0],0,+) // after V = I[0]; merge(V,0,+)
Defensive patterns
Strategy: validation
Validate before calling
// ensure first merge argument is a plain variable, not I[#i] or a reference merge_target = V # plain variable only
Try / catch
try { run(expr) } catch (CImgArgumentException &e) { log(e.what()); } Prevention
- Only pass plain vector variables to merge()
- Materialize references into new variables before merging
- Review custom commands for indexed first arguments
When it happens
Trigger: Calling merge() with a first argument that resolves to a linked/reference vector, such as passing an indexed slice, a dereferenced named reference, or the result of a reference-returning expression instead of a plain variable.
Common situations: Passing 'I[#ind]' style indexed values, or a variable previously assigned by reference, into merge() in a G'MIC/CImg custom command.
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<
- [" cimg_appname "_math_parser] CImg<
- [" cimg_appname "_math_parser] CImg<
- "[" cimg_appname "_math_parser] CImg<
- [" cimg_appname "_math_parser] CImg<
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/0ca0aa9cc3905651.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:22685
}
if (!std::strncmp(ss,"mse(",4)) { // Mean-squared error
_cimg_mp_op("Function 'mse()'");
s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
arg1 = compile(ss4,s1,depth1,0,block_flags);
arg2 = compile(++s1,se1,depth1,0,block_flags);
_cimg_mp_check_type(arg2,2,is_scalar(arg1)?1:2,size(arg1));
_cimg_mp_scalar3(mp_mse,arg1,arg2,size(arg1));
}
if (!std::strncmp(ss,"merge(",6)) { // Merge inter-thread variables
_cimg_mp_op("Function 'merge()'");
s1 = ss6; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;
ref.assign(7);
pos = compile(ss6,s1,depth1,ref,block_flags);
if (*ref) {
_cimg_mp_strerr;
throw CImgArgumentException("[" cimg_appname "_math_parser] "
"CImg<%s>::%s: %s: First argument cannot be a linked reference, "
"in expression '%s'.",
pixel_type(),_cimg_mp_calling_function,s_op,
s0);
}
arg1 = ~0U; // Merge operator
// (0='=',1='+',2='-',3='*',4='/',5='&',6='|',7='xor',8='&&',9=='||',10='min',11='max')
if (s1<se1) {
++s1;
char st_op[4] = {};
is_sth = false; // blank after operator?
if (cimg_sscanf(s1," %3[=+-*/&|minaxor]%c",st_op,&sep)==2 && (sep==')' ||
(is_sth=cimg::is_blank(sep)))) {
if (!is_sth || (is_sth && cimg_sscanf(s1," %*[=+-*/&|minaxor ]%c",&sep)==1 && sep==')')) {
cimg::strpare(st_op,' ',false,true);
if (!st_op[1])
arg1 = *st_op=='='?0:*st_op=='+'?1:*st_op=='-'?2:*st_op=='*'?3:*st_op=='/'?4:View on GitHub (pinned to f788b534b4)