Yalantis/uCrop · error · CImgArgumentException

Invalid sequence of filling values '%s'.

Error message

Invalid sequence of filling values '%s'.

What it means

CImg's fill_from_values() parses a C-string of space/comma-separated pixel values and fills the image with them. It first runs the internal _fill_from_values() parser; if that reports failure (the string is empty, malformed, or contains unparseable tokens) it throws this CImgArgumentException. The library throws it because continuing would leave the fill partially applied or silently wrong.

Source

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

      cimg::exception_mode(excmode);
      cimg_abort_test;
      return *this;
    }

    //! Fill sequentially pixel values according to a given expression \newinstance.
    CImg<T> get_fill(const char *const expression, const bool repeat_values, const bool allow_formula=true,
                     CImgList<T> *const list_images=0) const {
      return (+*this)._fill(expression,repeat_values,allow_formula?3:1,list_images,"fill",this,0);
    }

    //! Fill sequentially pixel values according to a value sequence, given as a string.
    /**
       \param values C-string describing a sequence of values.
       \param repeat_values Tells if this sequence must be repeated when filling.
    **/
    CImg<T>& fill_from_values(const char *const values, const bool repeat_values) {
      if (_fill_from_values(values,repeat_values))
        throw CImgArgumentException(_cimg_instance
                                    "Invalid sequence of filling values '%s'.",
                                    cimg_instance,values);
      return *this;
    }

    //! Fill sequentially pixel values according to a value sequence, given as a string \newinstance.
    CImg<T> get_fill_from_values(const char *const values, const bool repeat_values) const {
      return (+*this).fill_from_values(values,repeat_values);
    }

    // Fill image according to a value sequence, given as a string.
    // Return 'true' if an error occured, 'false' otherwise.
    bool _fill_from_values(const char *const values, const bool repeat_values) {
      CImg<charT> item(256);
      const char *nvalues = values;
      const ulongT siz = size();
      T *ptrd = _data;
      ulongT nb = 0;

View on GitHub (pinned to f788b534b4)

Solutions

  1. Print/log the values string right before the call and verify every token parses as a number in the current locale (use '.' as decimal separator).
  2. Check the string is non-null and non-empty before calling; guard against failed sprintf/snprintf which can leave the buffer empty.
  3. Count the supplied values against what the fill expects (with repeat_values=false the sequence must match the pixel count or a multiple pattern CImg accepts).
  4. If building from std::string, ensure it lives until after the fill_from_values call and pass .c_str() of a live object.

Example fix

// before
char buf[16];
snprintf(buf, sizeof buf, "%f %f", r); // truncated, missing second value
img.fill_from_values(buf, false); // throws
// after
char buf[64];
int n = snprintf(buf, sizeof buf, "%f %f", r, g);
if (n > 0 && buf[0] != '\0') img.fill_from_values(buf, false);
Defensive patterns

Strategy: validation

Validate before calling

bool validFillValues(const char* values) {
  if (!values || !*values) return false;
  for (const char* p = values; *p; ++p)
    if (!(isdigit((unsigned char)*p) || *p=='.' || *p=='-' || *p=='+' || *p=='e' || *p=='E' || isspace((unsigned char)*p) || *p==','))
      return false;
  return true;
}
if (validFillValues(vals)) img.fill_from_values(vals, repeat);

Try / catch

try {
  img.fill_from_values(values, repeat_values);
} catch (const CImgArgumentException& e) {
  std::fprintf(stderr, "fill_from_values rejected input '%s': %s\n", values, e.what());
}

Prevention

When it happens

Trigger: Calling CImg<T>::fill_from_values(const char* values, ...) with a null pointer, an empty string, or a string containing non-numeric tokens or a wrong number of values for the requested fill (e.g. "1 2 abc" or a truncated sequence when repeat_values is false).

Common situations: Programmatically constructing a fill string (e.g. with snprintf/sprintf) so it ends up empty or truncated; locale issues where decimal commas instead of dots break number parsing; passing a std::string via .c_str() after it went out of scope or was never populated; hand-edited value lists with typos.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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