{"record":{"id":"7500eb86f41d6ce9","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-s-7500eb","errorCode":null,"errorMessage":"[\" cimg_appname \"_math_parser] CImg<%s>::%s: %s%s %s%s has invalid type '%s' (should be %s), in expression '%s'.","messagePattern":"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>::(.+?): (.+?)(.+?) (.+?)(.+?) has invalid type '(.+?)' \\(should be (.+?)\\), in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":25253,"sourceCode":"        bool cond = false;\n        if (mode&1) cond|=_is_scalar;\n        if (mode&2) cond|=_is_vector;\n        if (!cond) {\n          const char *s_arg;\n          if (*s_op!='F') s_arg = !n_arg?\"\":n_arg==1?\"Left-hand\":\"Right-hand\";\n          else s_arg = s_argth(n_arg);\n          CImg<charT> sb_type(32);\n          if (mode==1) cimg_snprintf(sb_type,sb_type._width,\"'scalar'\");\n          else if (mode==2) {\n            if (N) cimg_snprintf(sb_type,sb_type._width,\"'vector%u'\",N);\n            else cimg_snprintf(sb_type,sb_type._width,\"'vector'\");\n          } else {\n            if (N) cimg_snprintf(sb_type,sb_type._width,\"'scalar' or 'vector%u'\",N);\n            else cimg_snprintf(sb_type,sb_type._width,\"'scalar' or 'vector'\");\n          }\n          char *s0;\n          _cimg_mp_strerr;\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                      \"CImg<%s>::%s: %s%s %s%s has invalid type '%s' (should be %s), \"\n                                      \"in expression '%s'.\",\n                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?\":\":\"\",\n                                      s_arg,*s_op=='F'?(*s_arg?\" argument\":\" Argument\"):(*s_arg?\" operand\":\" Operand\"),\n                                      s_type(arg)._data,sb_type._data,s0);\n        }\n      }\n\n      // Check that imglist are not empty.\n      void check_list(char *const ss, char *const se, const char saved_char) {\n        if (!imglist) {\n          char *s0;\n          _cimg_mp_strerr;\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                      \"CImg<%s>::%s: %s%s Image list cannot be empty, for expression '%s'.\",\n                                      pixel_type(),_cimg_mp_calling_function,s_op,*s_op?\":\":\"\",s0);\n        }\n      }","sourceCodeStart":25235,"sourceCodeEnd":25271,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L25235-L25271","documentation":"The math parser type-checks arguments/operands against the expected kind (scalar or a vector of expected dimension N). When an operand has the wrong type — e.g. a vector where a scalar is required, or a vector of the wrong dimension — this CImgArgumentException is thrown. The message shows the actual type via s_type(arg) and the expected type string.","triggerScenarios":"Calling an MP function like 'norm(v)' with a matrix-typed value, or passing a vectorN where scalar/vectorM is required, e.g. 'pand(a,[1,2])' with scalar a expected.","commonSituations":"Typos in expression variables; misremembering function signatures (vector vs scalar args); wrapping constants in brackets producing unintended vectors.","solutions":["Match the expected type shown in the message: wrap scalars or use [ ] for vectors as needed.","Check the CImg documentation for the exact argument types of the function used.","Correct vector dimension to the required vectorN size.","Test the sub-expression standalone to isolate which operand has the wrong type."],"exampleFix":"// before\nimg.fill(\"norm([1,2,3],[4,5])\"); // second operand wrong dimension\n// after\nimg.fill(\"norm([1,2,3],[4,5,6])\");","handlingStrategy":"type-guard","validationCode":"// Verify operand kind before composing expression\nbool scalarOk = std::isfinite(value);","typeGuard":"bool isScalarArg(const std::string& tok) { return tok.find(',') == std::string::npos && tok.front() != '['; }","tryCatchPattern":"try { img.fill(expr); } catch (const cimg_library::CImgArgumentException& e) { /* fix operand type per message */ }","preventionTips":["Consult function signature docs for scalar vs vector args","Avoid accidental [x] wrapping of scalars","Test sub-expressions in isolation"],"tags":["cimg","math-parser","type-mismatch","expression"],"backgroundTag":"type-mismatch","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"}