{"record":{"id":"58eb0a53bb9d654d","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-targe","errorCode":null,"errorMessage":"[cimg_appname_math_parser] CImg<%s>::%s: %s: Target scalar is constant, in expression '%s'.","messagePattern":"\\[cimg_appname_math_parser\\] CImg<(.+?)>::(.+?): (.+?): Target scalar is constant, in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":21768,"sourceCode":"              if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::factorial((int)mem[arg1]));\n              _cimg_mp_scalar1(mp_factorial,arg1);\n            }\n\n            if (!std::strncmp(ss,\"fibo(\",5)) { // Fibonacci\n              _cimg_mp_op(\"Function 'fibo()'\");\n              arg1 = compile(ss5,se1,depth1,0,block_flags);\n              if (is_vector(arg1)) _cimg_mp_vector1_v(mp_fibonacci,arg1);\n              if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::fibonacci((int)mem[arg1]));\n              _cimg_mp_scalar1(mp_fibonacci,arg1);\n            }\n\n            if (!std::strncmp(ss,\"fill(\",5)) { // Fill\n              _cimg_mp_op(\"Function 'fill()'\");\n              s0 = ss5; while (s0<se1 && (*s0!=',' || level[s0 - expr._data]!=clevel1)) ++s0;\n              arg1 = compile(ss5,s0,depth1,0,block_flags); // Object to fill\n              if (is_const_scalar(arg1)) {\n                _cimg_mp_strerr;\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: %s: Target scalar is constant, \"\n                                            \"in expression '%s'.\",\n                                            pixel_type(),_cimg_mp_calling_function,s_op,ss);\n              }\n              s1 = ++s0; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;\n              p1 = code._width;\n\n              if (s1<se1) { // Version with 3 arguments\n                variable_name.assign(s0,(unsigned int)(s1 + 1 - s0)).back() = 0;\n                cimg::strpare(variable_name,false,true);\n                if (!cimg::is_varname(variable_name)) { // Invalid variable name\n                  cimg::strellipsize(variable_name,64);\n                  _cimg_mp_strerr;\n                  throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                              \"CImg<%s>::%s: %s: Invalid loop variable name '%s', \"\n                                              \"in expression '%s'.\",\n                                              pixel_type(),_cimg_mp_calling_function,s_op,\n                                              variable_name._data,s0);","sourceCodeStart":21750,"sourceCodeEnd":21786,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L21750-L21786","documentation":"The math parser's `fill()` function requires its first argument to be a mutable target (vector/array slot). If the compiled first argument is a constant scalar (literal or constant-folded expression), there is nothing to fill, so CImg throws this CImgArgumentException at expression-compile time.","triggerScenarios":"Calling `fill(<constant>, ...)` inside a math expression, e.g. `img.fill(\"fill(3, vector(5))\")` where the first arg is the literal 3 rather than a named vector variable; also when the target expression is constant-folded into a scalar.","commonSituations":"Typos in variable names so the parser resolves a literal instead of a vector; misunderstanding that fill()'s first argument must be an lvalue-like vector reference; porting scripts where a variable was never declared with `vector(N)` or similar.","solutions":["Make the first argument a declared vector/variable (e.g. `v = vector(5); fill(v, value)`)","Declare the target before filling: use `vector(N)` or similar to allocate it","Fix typos in variable names that made the parser treat the argument as a literal","Use the direct CImg::fill(value) C++ method instead of the expression form for plain constant fills"],"exampleFix":"// before\nimg.fill(\"fill(3, [1,2,3])\"); // 3 is a constant scalar\n// after\nimg.fill(\"v = vector(3); fill(v,[1,2,3])\");","handlingStrategy":"validation","validationCode":"// Ensure the fill() target is a declared variable, not a literal:\n// bad: \"fill(3, ...)\"; good: \"v = vector(n); fill(v, ...)\"\nboolean fillTargetIsVariable(String expr) {\n  java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"fill\\\\(\\\\s*([^,)]+)\").matcher(expr);\n  return !m.find() || m.group(1).trim().matches(\"[A-Za-z_][A-Za-z0-9_]*\");\n}","typeGuard":null,"tryCatchPattern":"try { img.fill(expr); } catch (CImgArgumentException e) { if (e.getMessage().contains(\"Target scalar is constant\")) { throw new IllegalArgumentException(\"fill() target must be a declared vector/variable\"); } throw e; }","preventionTips":["Always declare the fill target with vector(N) or an assignment before calling fill()","Never pass literals as the first fill() argument","Avoid shadowing variables with constant expressions you later mutate"],"tags":["cimg","math-parser","const-correctness","expression-compilation"],"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"}