{"record":{"id":"6bbeee404c6d8c82","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-m","errorCode":null,"errorMessage":"[\" cimg_appname \"_math_parser] CImg<%s>::%s: %s: Merge has already been requested before for specified variable in expression '%s'.","messagePattern":"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>::(.+?): (.+?): Merge has already been requested before for specified variable in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":22716,"sourceCode":"                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:\n                        *st_op=='&'?5:*st_op=='|'?6:~0U;\n                    else if (*st_op=='x' && st_op[1]=='o' && st_op[2]=='r' && !st_op[3]) arg1 = 7;\n                    else if (*st_op=='&' && st_op[1]=='&' && !st_op[2]) arg1 = 8;\n                    else if (*st_op=='|' && st_op[1]=='|' && !st_op[2]) arg1 = 9;\n                    else if (*st_op=='m' && st_op[1]=='i' && st_op[2]=='n' && !st_op[3]) arg1 = 10;\n                    else if (*st_op=='m' && st_op[1]=='a' && st_op[2]=='x' && !st_op[3]) arg1 = 11;\n                  }\n                }\n              }\n\n              cimg_rofY(memmerge,k) if (memmerge(0,k)==(int)pos) {\n                _cimg_mp_strerr;\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: %s: Merge has already been requested before \"\n                                            \"for specified variable \"\n                                            \"in expression '%s'.\",\n                                            pixel_type(),_cimg_mp_calling_function,s_op,s0);\n              }\n              if (arg1==~0U) {\n                _cimg_mp_strerr;\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: %s: Invalid specified operator \"\n                                            \"(should be one of '=,+,-,*,/,&,|,xor,&&,||,min,max'), \"\n                                            \"in expression '%s'.\",\n                                            pixel_type(),_cimg_mp_calling_function,s_op,s0);\n              }\n              memmerge.resize(3,memmerge._height + 1,1,1,0,0);\n              memmerge(0,memmerge._height - 1) = (int)pos;\n              memmerge(1,memmerge._height - 1) = (int)size(pos);\n              memmerge(2,memmerge._height - 1) = (int)arg1;\n              _cimg_mp_return_nan();","sourceCodeStart":22698,"sourceCodeEnd":22734,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L22698-L22734","documentation":"The math parser tracks requested merges per variable in the memmerge table. If the same variable position appears more than once as a merge target, the parser throws because two merge requests on one variable are ambiguous and unsupported within a single expression.","triggerScenarios":"Calling merge() twice (or having two merge ops) on the same variable within one expression, e.g. 'merge(V,0,+); merge(V,1,min)'.","commonSituations":"Copy-pasting merge lines in a custom command, or a loop unrolled in an expression that repeatedly merges into the same accumulator variable.","solutions":["Use a distinct target variable for each merge operation","Combine the merges into one call if the operator is the same","Restructure the expression so the variable is merged once (e.g. accumulate into a temporary then assign)","Split the computation into multiple expressions/runs if two merges are truly needed"],"exampleFix":"// before\nmerge(V,0,+); merge(V,0,min)\n// after\nmerge(V,0,+); W = 0; merge(W,0,min)","handlingStrategy":"validation","validationCode":"// track merge targets per expression; each variable may appear once\nmerged_vars = [] # assert V not already merged in this expression","typeGuard":null,"tryCatchPattern":"try { run(expr) } catch (CImgArgumentException &e) { log(e.what()); }","preventionTips":["One merge per variable per expression","Use distinct accumulator variables","Split expressions that need repeated merges"],"tags":["cimg","math-parser","merge","duplicate"],"backgroundTag":"invalid-state-transition","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"}