{"record":{"id":"a8676acc8fc81c68","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-a8676a","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'polygon()': Invalid arguments '%s'. \"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'polygon\\(\\)': Invalid arguments '(.+?)'\\. \"","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":29238,"sourceCode":"              if (i<i_end) opacity = (float)_mp_arg(i++);\n              if (is_outlined && i<i_end) {\n                double d_pattern = _mp_arg(i++);\n                if (d_pattern<0) { d_pattern = -d_pattern; is_closed = false; }\n                pattern = (unsigned int)d_pattern;\n              }\n              cimg_forX(color,k) if (i<i_end) color[k] = (T)_mp_arg(i++);\n              else { color.resize(k,1,1,1,-1); break; }\n              color.resize(img._spectrum,1,1,1,0,2);\n              if (is_outlined) img.draw_polygon(points,color._data,opacity,pattern,is_closed);\n              else img.draw_polygon(points,color._data,opacity);\n            }\n          }\n        }\n        if (is_invalid_arguments) {\n          CImg<doubleT> args(i_end - 4);\n          cimg_forX(args,k) args[k] = _mp_arg(4 + k);\n          if (ind==~0U)\n            throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'polygon()': \"\n                                        \"Invalid arguments '%s'. \",\n                                        mp.imgin.pixel_type(),args.value_string()._data);\n          else\n            throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'polygon()': \"\n                                        \"Invalid arguments '#%u%s%s'. \",\n                                        mp.imgin.pixel_type(),ind,args._width?\",\":\"\",args.value_string()._data);\n        }\n        return cimg::type<double>::nan();\n      }\n\n      static double mp_pow(_cimg_math_parser& mp) {\n        const double v = _mp_arg(2), p = _mp_arg(3);\n        return std::pow(v,p);\n      }\n\n      static double mp_pow0_25(_cimg_math_parser& mp) {\n        const double val = _mp_arg(2);\n        return std::sqrt(std::sqrt(val));","sourceCodeStart":29220,"sourceCodeEnd":29256,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L29220-L29256","documentation":"The math parser 'polygon()' draw command validates its argument list (the coordinates/points passed after the drawing parameters). When the arguments don't match the expected format, it collects the parsed argument values and throws a CImgArgumentException listing the invalid arguments. This variant fires when no target image index (ind==~0U) was specified.","triggerScenarios":"An expression like polygon(..., badArgs) where the argument tuple cannot be interpreted as a valid point sequence — wrong number of coordinates, non-numeric values, or the arguments resolved to NaN, causing is_invalid_arguments to be set.","commonSituations":"Building polygon point lists programmatically with a bug producing NaN; mismatched point counts (odd number of coordinate values when pairs are expected); passing image-index-targeted syntax incorrectly.","solutions":["Inspect the argument string in the error message and correct the malformed polygon arguments.","Ensure coordinates are finite numbers (no NaN/Inf from divisions by zero upstream).","Supply coordinate pairs (x,y[,z]) so the total argument count matches the expected geometry.","If targeting a specific image, use the '#ind' form so the correct error variant and validation path applies."],"exampleFix":"// before: polygon(-1,0,X,Y,Z, 0,0,0)   // wrong arg count/NaN\n// after:  polygon(-1,0,X0,Y0,X1,Y1,opacity)","handlingStrategy":"try-catch","validationCode":"// ensure all coordinates finite and even count before building the expression\nbool ok = !coords.empty() && coords.size() % 2 == 0 &&\n          std::all_of(coords.begin(), coords.end(),\n                      [](double v){ return std::isfinite(v); });","typeGuard":"auto isFiniteArgs = [](const std::vector<double>& a) {\n  return std::all_of(a.begin(), a.end(), [](double v){ return std::isfinite(v); });\n};","tryCatchPattern":"try { result = img.evaluate(drawExpr); } catch (const CImgArgumentException& e) { log(\"polygon args rejected: \" << e.what()); }","preventionTips":["Sanitize coordinates for NaN/Inf before expression build","Keep point-count parity (pairs of x,y)","Cover polygon argument formats in unit tests"],"tags":["cimg","math-parser","invalid-argument"],"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"}