{"record":{"id":"f10db819100f29ba","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-s","errorCode":null,"errorMessage":"[\" cimg_appname \"_math_parser] CImg<%s>::%s: %s%s %s%s (of type '%s') is not a constant, in expression '%s'.","messagePattern":"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>::(.+?): (.+?)(.+?) (.+?)(.+?) \\(of type '(.+?)'\\) is not a constant, in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":25154,"sourceCode":"      }\n\n      // Return size of specified value (0: scalar, N>0: vectorN).\n      unsigned int size(const unsigned int arg) const {\n        return is_scalar(arg)?0U:memtype[arg] - 1U;\n      }\n\n      // Check if a memory slot is a positive integer constant scalar value.\n      // 'mode' can be:\n      // { 0=constant | 1=integer constant | 2=positive integer constant | 3=strictly-positive integer constant }.\n      void check_const_scalar(const unsigned int arg, const unsigned int n_arg,\n                              const unsigned int mode,\n                              char *const ss, char *const se, const char saved_char) {\n        _cimg_mp_check_type(arg,n_arg,1,0);\n        if (!is_const_scalar(arg)) {\n          const char *const s_arg = s_argth(n_arg);\n          char *s0;\n          _cimg_mp_strerr;\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                      \"CImg<%s>::%s: %s%s %s%s (of type '%s') is not a constant, \"\n                                      \"in expression '%s'.\",\n                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?\":\":\"\",\n                                      s_arg,*s_arg?\" argument\":\" Argument\",s_type(arg)._data,s0);\n        }\n        const double val = mem[arg];\n\n        if (!((!mode || (double)(int)mem[arg]==mem[arg]) &&\n              (mode<2 || mem[arg]>=(mode==3)))) {\n          const char *const s_arg = s_argth(n_arg);\n          char *s0;\n          _cimg_mp_strerr;\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                      \"CImg<%s>::%s: %s%s %s%s (of type '%s' and value %g) is not a%s constant, \"\n                                      \"in expression '%s'.\",\n                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?\":\":\"\",\n                                      s_arg,*s_arg?\" argument\":\" Argument\",s_type(arg)._data,val,\n                                      !mode?\"\":mode==1?\"n integer\":","sourceCodeStart":25136,"sourceCodeEnd":25172,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L25136-L25172","documentation":"The CImg math parser includes constructs (e.g. certain function arguments and compile-time values like image indices or sizes) that must be compile-time constants. check_constant() calls _cimg_mp_check_type and then rejects any argument for which is_const_scalar() is false, throwing CImgArgumentException that names the operator/function, argument position, and the actual type found.","triggerScenarios":"Passing a runtime-varying expression (a vector, a reference to image pixel data, or a computed non-scalar) where a constant scalar is required, e.g. using a variable or pixel value where a literal number is expected, such as an argument that must be fixed at compile time (resize factor, axis, index literal).","commonSituations":"Using image-dependent values (like I[x]) or user variables in positions that must be literal constants; porting scripts where a parameter was a literal in an older version but the call site now computes it; misunderstanding which arguments of a function are compile-time-only.","solutions":["Replace the non-constant argument with a literal numeric constant","If the value depends on runtime data, compute it outside the expression (in C++ code) and inject it into the expression string as a formatted literal","Check the function signature in CImg.h to confirm which arguments must be constant scalars","Use is_const_scalar-compatible values: numeric literals or const-foldable subexpressions only"],"exampleFix":"// before\ndouble f = get_factor();\nimg.fill(\"resize({f},2)\"); // 'f' not usable as constant in this position\n// after\ndouble f = get_factor();\nchar expr[64];\nsnprintf(expr, sizeof(expr), \"resize(%g,2)\", f); // inject literal\nimg.fill(expr);","handlingStrategy":"validation","validationCode":"// C++: ensure arguments that must be constants are formatted literals\nstd::string make_expr(double required_const) {\n  char buf[64];\n  std::snprintf(buf, sizeof(buf), \"op(%g,2)\", required_const);\n  return std::string(buf); // value embedded as literal, not a runtime symbol\n}","typeGuard":null,"tryCatchPattern":"try {\n  img.fill(expr.c_str());\n} catch (const cimg_library::CImgArgumentException& e) {\n  std::cerr << \"Non-constant argument in expression: \" << e.what() << std::endl;\n}","preventionTips":["Treat compile-time-constant parameters as literals: format them into the string","Never pass pixel/vector-derived values where a scalar constant is documented as required","Consult the CImg function docs for which arguments must be constants"],"tags":["cimg","math-parser","constant-expression","argument-validation"],"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-14T05:17:10.506Z"}