{"record":{"id":"97131e19f68778f7","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-s-97131e","errorCode":null,"errorMessage":"[\" cimg_appname \"_math_parser] CImg<%s>::%s: %s%s Specified image index is not a constant, in expression '%s'.","messagePattern":"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>::(.+?): (.+?)(.+?) Specified image index is not a constant, in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":25183,"sourceCode":"          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\":\n                                      mode==2?\" positive integer\":\" strictly positive integer\",s0);\n        }\n      }\n\n      // Check if an image index is a constant value.\n      void check_const_index(const unsigned int arg,\n                             char *const ss, char *const se, const char saved_char) {\n        if (arg!=~0U && !is_const_scalar(arg)) {\n          char *s0;\n          _cimg_mp_strerr;\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                      \"CImg<%s>::%s: %s%s Specified image index is not a constant, \"\n                                      \"in expression '%s'.\",\n                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?\":\":\"\",s0);\n        }\n      }\n\n      // Check that specified constant is not nan.\n      void check_notnan_index(const unsigned int arg, const char *const s_arg,\n                              char *const ss, char *const se, const char saved_char) {\n        if (arg!=~0U &&\n            (arg==_cimg_mp_slot_nan || (is_const_scalar(arg) && cimg::type<double>::is_nan(mem[arg])))) {\n          char *s0;\n          _cimg_mp_strerr;\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                      \"CImg<%s>::%s: %s%s Specified index '%s' is NaN.\",\n                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?\":\":\"\",s_arg);\n        }\n      }","sourceCodeStart":25165,"sourceCodeEnd":25201,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L25165-L25201","documentation":"check_const_index() validates that an image-index argument inside a math expression is a compile-time constant scalar. Multi-image expressions in CImg reference images by index (e.g. I0, I[#1,...] style access or functions taking an image number), and these indices must be resolvable at compile time. If the index expression is not a constant scalar, the parser throws CImgArgumentException.","triggerScenarios":"Using a computed or runtime expression as an image index, e.g. I[#(z+1),...] or passing a variable/pixel-derived value where a literal image number like 0 or 1 is required; arg==~0U (no index) is allowed, but any non-constant index argument is rejected.","commonSituations":"Trying to iterate over image indices inside the expression language (loops over image numbers); using per-pixel values to select an image dynamically; porting scripts where dynamic image selection seemed supported but is not at parse time.","solutions":["Replace the dynamic image index with a literal integer index","If you need to process several images, loop in C++ and call the expression per image index, injecting the literal index via snprintf","Restructure the expression so the image selection happens outside the expression (e.g. select the image with img.select() before evaluation)","Use compile-time constant subexpressions (numeric literals, const variables) for the index argument"],"exampleFix":"// before\nimg.fill(\"I[#(z)]\"); // dynamic image index not allowed\n// after\nfor (int k = 0; k < nb_images; ++k) {\n  char expr[64];\n  snprintf(expr, sizeof(expr), \"I[#%d]\", k);\n  images[k].fill(expr); // literal constant index\n}","handlingStrategy":"validation","validationCode":"// C++: only allow literal indices; reject anything else before the CImg call\nstd::string make_indexed_expr(int image_index) {\n  if (image_index < 0) throw std::invalid_argument(\"image index must be a constant >= 0\");\n  char buf[64];\n  std::snprintf(buf, sizeof(buf), \"I[#%d]\", image_index);\n  return std::string(buf);\n}","typeGuard":"bool is_literal_index(const std::string& idx_expr) {\n  return !idx_expr.empty() &&\n         idx_expr.find_first_not_of(\"0123456789\") == std::string::npos;\n}","tryCatchPattern":"try {\n  img.fill(expr.c_str());\n} catch (const cimg_library::CImgArgumentException& e) {\n  std::cerr << \"Image index must be constant: \" << e.what() << std::endl;\n}","preventionTips":["Never compute image indices inside the expression language; select images in C++ instead","Loop over images in host code and inject literal indices via snprintf","Keep expressions that reference multiple images limited to numeric literal indices"],"tags":["cimg","math-parser","image-index","constant-expression"],"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"}