Yalantis/uCrop · error · CImgArgumentException

"[" cimg_appname "_math_parser] CImg<

Error message

"[" cimg_appname "_math_parser] CImg<%s>: Function 'ellipse()': Invalid arguments '%s'. "

What it means

The math parser's ellipse() function expects either a fixed set of scalar arguments or a valid image index selector. This variant is thrown when no image selector (#ind) was given (ind==~0U) but the argument list does not match any supported ellipse() overload, so the collected extra arguments cannot be dispatched.

Solutions

  1. Check the ellipse() signature in your CImg version and supply the exact expected arguments (x,y,radius1,radius2,angle,color,...).
  2. Add the #image_index selector if you meant to draw on a specific image.
  3. Count the provided arguments — the message echoes them via value_string to spot extras/missing ones.
  4. Update the expression if it was written for a different CImg version with different arity.

Example fix

// before: missing second radius
 ellipse(x,y,r,angle)
// after
 ellipse(x,y,r1,r2,angle)
Defensive patterns

Strategy: validation

Validate before calling

// Validate ellipse() argument count against the expected signature before evaluation
const ELLIPSE_MIN_ARGS = 5; // x,y,r1,r2,angle
function checkEllipseArgs(args) { if (args.length < ELLIPSE_MIN_ARGS) throw new Error('ellipse() needs at least ' + ELLIPSE_MIN_ARGS + ' args, got ' + args.length); }

Type guard

function hasValidEllipseArity(args) { return [5,6,7,8].includes(args.length); }

Try / catch

try { evalMath(expr); } catch (e) { if (String(e).includes("Function 'ellipse()'") && String(e).includes('Invalid arguments')) { console.error('bad ellipse args:', e.message); fixExpr(); } else throw e; }

Prevention

When it happens

Trigger: Calling ellipse() in a math expression with an argument count or types that match no supported signature (e.g. wrong number of radii/angle/color arguments) without a #index prefix.

Common situations: Typos in argument count (missing radius or angle); passing color as multiple scalars beyond the supported arity; porting scripts between CImg versions where ellipse() gained/lost overloads.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/a8429ec2bbdec4fe. Report an issue: GitHub.

Appendix: source

Thrown at ucrop/src/main/jni/CImg.h:26709

                    if (i<i_end) {
                      cimg_forX(color,k) if (i<i_end) color[k] = (T)_mp_arg(i++);
                      else { color.resize(k,1,1,1,-1); break; }
                      color.resize(img._spectrum,1,1,1,0,2);
                    }
                  }
                }
              }
            }
          }
        }
        if (!is_invalid_arguments) {
          if (is_outlined) img.draw_ellipse(x0,y0,r1,r2,angle,color._data,opacity,pattern);
          else img.draw_ellipse(x0,y0,r1,r2,angle,color._data,opacity);
        } else {
          CImg<doubleT> args(i_end - 4);
          cimg_forX(args,k) args[k] = _mp_arg(4 + k);
          if (ind==~0U)
            throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'ellipse()': "
                                        "Invalid arguments '%s'. ",
                                        mp.imgin.pixel_type(),args.value_string()._data);
          else
            throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'ellipse()': "
                                        "Invalid arguments '#%u%s%s'. ",
                                        mp.imgin.pixel_type(),ind,args._width?",":"",args.value_string()._data);
        }
        return cimg::type<double>::nan();
      }

      static double mp_epoch(_cimg_math_parser& mp) {
        unsigned int
          year = (unsigned int)mp.opcode[2]==~0U?~0U:(unsigned int)std::max(_mp_arg(2),1900.),
          month = (unsigned int)mp.opcode[3]==~0U?~0U:(unsigned int)cimg::cut(_mp_arg(3),1.,12.),
          day = (unsigned int)mp.opcode[4]==~0U?~0U:(unsigned int)cimg::cut(_mp_arg(4),1.,31.),
          hour = (unsigned int)mp.opcode[5]==~0U?~0U:(unsigned int)cimg::cut(_mp_arg(5),0.,23.),
          minute = (unsigned int)mp.opcode[6]==~0U?~0U:(unsigned int)cimg::cut(_mp_arg(6),0.,59.),
          second = (unsigned int)mp.opcode[7]==~0U?~0U:(unsigned int)cimg::cut(_mp_arg(7),0.,60.);

View on GitHub (pinned to f788b534b4)