Yalantis/uCrop · error · CImgArgumentException

get_shared_images(): Specified sub-list indices (%u->%u) are

Error message

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

What it means

The non-const CImgList::get_shared_images(pos0,pos1) throws the same range error as get_images: pos0 > pos1 or pos1 >= _width is rejected. Shared images alias the list's pixel buffers, so the indices must resolve to existing elements.

Source

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

    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,
                                    pos0,pos1);
      CImgList<T> res(pos1 - pos0 + 1);
      cimglist_for(res,l) res[l].assign(_data[pos0 + l],_data[pos0 + l]?true:false);
      return res;
    }

    //! Return a shared sublist \newinstance.
    const CImgList<T> get_shared_images(const unsigned int pos0, const unsigned int pos1) const {
      if (pos0>pos1 || pos1>=_width)
        throw CImgArgumentException(_cimglist_instance
                                    "get_shared_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],_data[pos0 + l]?true:false);
      return res;

View on GitHub (pinned to f788b534b4)

Solutions

  1. Clamp/validate indices: require pos0 <= pos1 < list.size() before the call
  2. Check list.size() first and return an empty list when the range is invalid
  3. Swap arguments if the order may be reversed

Example fix

// before
CImgList<float> views = list.get_shared_images(2, 9); // throws if size < 10
// after
if (list.size() >= 10) {
  CImgList<float> views = list.get_shared_images(2, 9);
}
Defensive patterns

Strategy: validation

Validate before calling

if (pos0 <= pos1 && pos1 < list.size()) { /* safe to request shared views */ }

Try / catch

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

Prevention

When it happens

Trigger: list.get_shared_images(a,b) with a > b or b >= list.size(), e.g. requesting shared views 0..9 of a 4-image list.

Common situations: Creating shared views for in-place editing with stale size assumptions; slicing code shared with another container of different length.

Related errors


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