{"record":{"id":"cdb2b67b8dac4779","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-s-ar-cdb2b6","errorCode":null,"errorMessage":"[cimg_appname_math_parser] CImg<%s>::%s: %s: %s argument cannot be a constant, in expression '%s'.","messagePattern":"\\[cimg_appname_math_parser\\] CImg<(.+?)>::(.+?): (.+?): (.+?) argument cannot be a constant, in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":23712,"sourceCode":"                _cimg_mp_check_notnan_index(p1,ss6);\n                _cimg_mp_check_list();\n                s1 = s0; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1; // pos0\n                arg1 = compile(s0,s1,depth1,0,block_flags);\n                s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2; // pos1\n                arg2 = compile(s1,s2,depth1,0,block_flags);\n                arg3 = s2<se1?compile(++s2,se1,depth1,0,block_flags):0; // is_vector?\n                CImg<ulongT>::vector((ulongT)mp_image_swap,_cimg_mp_slot_nan,p1,arg1,arg2,arg3).move_to(code);\n\n              } else {\n                s1 = ss5; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;\n                ref.assign(14);\n                arg1 = compile(ss5,s1,depth1,ref,block_flags);\n                arg2 = compile(++s1,se1,depth1,ref._data + 7,block_flags);\n                p1 = size(arg1);\n                _cimg_mp_check_type(arg2,2,p1?2:1,p1);\n                if (is_const_scalar(arg1) || is_const_scalar(arg2)) {\n                  _cimg_mp_strerr;\n                  throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                              \"CImg<%s>::%s: %s: %s argument cannot be a constant, \"\n                                              \"in expression '%s'.\",\n                                              pixel_type(),_cimg_mp_calling_function,s_op,\n                                              is_const_scalar(arg1)?\"First\":\"Second\",s0);\n                }\n                CImg<ulongT>::vector((ulongT)mp_swap,arg1,arg2,p1).move_to(code);\n\n                // Write back values of linked arg1 and arg2.\n                const unsigned int *_ref = ref;\n                is_sth = true; // Is first argument?\n                do {\n                  switch (*_ref) {\n                  case 1 : // arg1: V[k]\n                    arg3 = _ref[1]; // Vector slot\n                    arg4 = _ref[2]; // Index\n                    CImg<ulongT>::vector((ulongT)mp_vector_set_off,arg1,arg3,(ulongT)size(arg3),arg4).\n                      move_to(code);\n                    break;","sourceCodeStart":23694,"sourceCodeEnd":23730,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L23694-L23730","documentation":"The swap-style opcode exchanges the contents of its two operands, so both must be writable (mutable, non-constant) slots in the parser's memory. If either compiled argument is a constant scalar/vector, compilation fails naming which one (First or Second) is constant.","triggerScenarios":"Calling swap(a,b) where a or b is a literal (e.g. swap(1,x)), a const vector, or an expression result rather than a named variable/vector slot.","commonSituations":"Trying to swap into a constant; passing literals by accident; shadowing a variable with a constant; misunderstanding that swap mutates in place and requires lvalues.","solutions":["Ensure both arguments are named variables/vectors declared with scalar()/vector(name) and assigned at runtime.","Replace literals with variables initialized to the literal value before swapping.","Check that you did not accidentally pass a pre-defined constant as one operand."],"exampleFix":"// before\n'swap(1,x)'\n// after\n'a=1; swap(a,x)'","handlingStrategy":"type-guard","validationCode":"// both operands must be declared, mutable variables\nif (!declaredVars.has(a) || !declaredVars.has(b)) throw new Error('swap operands must be mutable variables');","typeGuard":"const isMutableVar = (tok) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(tok) && declaredVars.has(tok) && !constNames.has(tok);","tryCatchPattern":"try { img.eval(expr); } catch (e) { if (/argument cannot be a constant/.test(e.message)) { /* replace literal operand with a variable */ } else throw e; }","preventionTips":["Never pass literals or constants to swap-like mutating opcodes.","Initialize a variable to hold any literal you need to swap.","Maintain a constness set in your expression builder."],"tags":["cimg","math-parser","constness"],"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"}