Yalantis/uCrop · error · CImgArgumentException

images(): Specified sub-list indices (%u->%u) are out of bou

Error message

images(): Specified sub-list indices (%u->%u) are out of bounds.

What it means

CImgList::get_images(pos0,pos1) returns a copy sublist and throws when pos0 > pos1 or pos1 >= _width, i.e. the requested index range is empty, reversed, or extends past the end of the list. The indices must satisfy pos0 <= pos1 < size().

Source

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

    //! Reverse list order \newinstance.
    CImgList<T> get_reverse() const {
      return (+*this).reverse();
    }

    //! Return a sublist.
    /**
      \param pos0 Starting index of the sublist.
      \param pos1 Ending index of the sublist.
    **/
    CImgList<T>& images(const unsigned int pos0, const unsigned int pos1) {
      return get_images(pos0,pos1).move_to(*this);
    }

    //! Return a sublist \newinstance.
    CImgList<T> get_images(const unsigned int pos0, const unsigned int pos1) const {
      if (pos0>pos1 || pos1>=_width)
        throw CImgArgumentException(_cimglist_instance
                                    "images(): Specified sub-list indices (%u->%u) are out of bounds.",
                                    cimglist_instance,
                                    pos0,pos1);
      CImgList<T> res(pos1 - pos0 + 1);
      cimglist_for(res,l) res[l].assign(_data[pos0 + l]);
      return res;
    }

    //! Return a shared sublist.
    /**
      \param pos0 Starting index of the sublist.
      \param pos1 Ending index of the sublist.
    **/
    CImgList<T> get_shared_images(const unsigned int pos0, const unsigned int pos1) {
      if (pos0>pos1 || pos1>=_width)
        throw CImgArgumentException(_cimglist_instance
                                    "get_shared_images(): Specified sub-list indices (%u->%u) are out of bounds.",
                                    cimglist_instance,

View on GitHub (pinned to f788b534b4)

Solutions

  1. Validate pos0 <= pos1 and pos1 < list.size() before calling, or clamp both
  2. If order may be reversed, swap pos0/pos1 first
  3. Check that the list is non-empty and large enough for the desired slice

Example fix

// before
CImgList<float> sub = list.get_images(0, 10); // throws if size < 11
// after
const unsigned int end = std::min(10u, list.size() - 1);
CImgList<float> sub = list.size() ? list.get_images(0, end) : CImgList<float>();
Defensive patterns

Strategy: validation

Validate before calling

bool valid = pos0 <= pos1 && !list.is_empty() && pos1 < list.size();

Try / catch

try { sub = list.get_images(pos0, pos1); } catch (const CImgArgumentException& e) { sub = CImgList<T>(); }

Prevention

When it happens

Trigger: list.get_images(3,1) (reversed order), list.get_images(0,10) on a 5-element list, or slicing an empty list.

Common situations: Python-style slicing habits where reversed ranges yield empty results; end index computed as start+count instead of start+count-1; slicing after the list was resized smaller.

Related errors


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