{"record":{"id":"42f542badb20e3d7","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-42f542","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'polygon()': Invalid arguments '#%u%s%s'. \"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'polygon\\(\\)': Invalid arguments '#%u(.+?)(.+?)'\\. \"","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":29242,"sourceCode":"                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));\n      }\n\n      static double mp_pow3(_cimg_math_parser& mp) {\n        const double val = _mp_arg(2);","sourceCodeStart":29224,"sourceCodeEnd":29260,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L29224-L29260","documentation":"Same invalid-arguments check as the unnamed-target variant of 'polygon()', but this branch throws when a specific target image index is given: the message is prefixed with '#<ind>' followed by the offending argument values, telling you which image slot received the malformed polygon arguments.","triggerScenarios":"polygon(#ind,...) in a math expression where the argument list after the target index is invalid — non-finite coordinates, wrong arity, or values that fail the parser's argument validation (is_invalid_arguments set).","commonSituations":"Vectorized drawing loops where one iteration produces NaN coordinates; switching draw targets (renumbering #ind) without updating the argument layout; passing an extra or missing opacity argument.","solutions":["Read the '#ind' and argument list from the message to find the bad values, then fix them in the expression.","Guard coordinate expressions so they never evaluate to NaN (e.g. clamp denominators before dividing).","Match the argument count to the expected polygon format (pairs of coordinates plus optional opacity).","Catch CImgArgumentException around draw expression evaluation to log the offending arguments."],"exampleFix":"// before: polygon(#0,0,X,Y,0/0)\n// after:  polygon(#0,0,X,Y,1)","handlingStrategy":"try-catch","validationCode":"if (ind < 0 || ind >= (int)images.size()) throw std::runtime_error(\"bad #ind for polygon\");\nif (!std::all_of(args.begin(), args.end(), [](double v){ return std::isfinite(v); }))\n  throw std::runtime_error(\"non-finite polygon argument\");","typeGuard":null,"tryCatchPattern":"try { img.evaluate(expr); } catch (const CImgArgumentException& e) { /* e.what() includes #ind and bad args */ }","preventionTips":["Validate the #ind target exists before drawing","Clamp divisions to avoid NaN coordinates in loops","Log the argument list on failure for quick diagnosis"],"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"}