{"record":{"id":"0ca0aa9cc3905651","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-f","errorCode":null,"errorMessage":"[\" cimg_appname \"_math_parser] CImg<%s>::%s: %s: First argument cannot be a linked reference, in expression '%s'.","messagePattern":"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>::(.+?): (.+?): First argument cannot be a linked reference, in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":22685,"sourceCode":"            }\n\n            if (!std::strncmp(ss,\"mse(\",4)) { // Mean-squared error\n              _cimg_mp_op(\"Function 'mse()'\");\n              s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;\n              arg1 = compile(ss4,s1,depth1,0,block_flags);\n              arg2 = compile(++s1,se1,depth1,0,block_flags);\n              _cimg_mp_check_type(arg2,2,is_scalar(arg1)?1:2,size(arg1));\n              _cimg_mp_scalar3(mp_mse,arg1,arg2,size(arg1));\n            }\n\n            if (!std::strncmp(ss,\"merge(\",6)) { // Merge inter-thread variables\n              _cimg_mp_op(\"Function 'merge()'\");\n              s1 = ss6; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;\n              ref.assign(7);\n              pos = compile(ss6,s1,depth1,ref,block_flags);\n              if (*ref) {\n                _cimg_mp_strerr;\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: %s: First argument cannot be a linked reference, \"\n                                            \"in expression '%s'.\",\n                                            pixel_type(),_cimg_mp_calling_function,s_op,\n                                            s0);\n              }\n\n              arg1 = ~0U; // Merge operator\n                          // (0='=',1='+',2='-',3='*',4='/',5='&',6='|',7='xor',8='&&',9=='||',10='min',11='max')\n              if (s1<se1) {\n                ++s1;\n                char st_op[4] = {};\n                is_sth = false; // blank after operator?\n                if (cimg_sscanf(s1,\" %3[=+-*/&|minaxor]%c\",st_op,&sep)==2 && (sep==')' ||\n                                                                              (is_sth=cimg::is_blank(sep)))) {\n                  if (!is_sth || (is_sth && cimg_sscanf(s1,\" %*[=+-*/&|minaxor ]%c\",&sep)==1 && sep==')')) {\n                    cimg::strpare(st_op,' ',false,true);\n                    if (!st_op[1])\n                      arg1 = *st_op=='='?0:*st_op=='+'?1:*st_op=='-'?2:*st_op=='*'?3:*st_op=='/'?4:","sourceCodeStart":22667,"sourceCodeEnd":22703,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L22667-L22703","documentation":"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.","triggerScenarios":"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.","commonSituations":"Passing 'I[#ind]' style indexed values, or a variable previously assigned by reference, into merge() in a G'MIC/CImg custom command.","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"],"exampleFix":"// before\nmerge(I[0],0,+)\n// after\nV = I[0]; merge(V,0,+)","handlingStrategy":"validation","validationCode":"// ensure first merge argument is a plain variable, not I[#i] or a reference\nmerge_target = V # plain variable only","typeGuard":null,"tryCatchPattern":"try { run(expr) } catch (CImgArgumentException &e) { log(e.what()); }","preventionTips":["Only pass plain vector variables to merge()","Materialize references into new variables before merging","Review custom commands for indexed first arguments"],"tags":["cimg","math-parser","merge","reference"],"backgroundTag":"invalid-argument-value","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}