Yalantis/uCrop · error · CImgArgumentException

get_shared_points(): Invalid request of a shared-memory…

Error message

get_shared_points(): Invalid request of a shared-memory subset (%u->%u,%u,%u,%u).

What it means

CImg<T>::get_shared_points() returns a shared-memory 1D image referencing the pixels from x0 to x1 at (y0,z0,c0). It throws CImgArgumentException when the computed offsets are inconsistent or out of bounds: beg > end, beg >= size(), or end >= size() of the instance.

Solutions

  1. Ensure x0 <= x1 and x1 < img.width() (indices are inclusive bounds).
  2. Clamp the range before the call: x0 = std::min(x0, img.width()-1); x1 = std::min(x1, img.width()-1);
  3. Verify y0/z0/c0 are within _height/_depth/_spectrum; a bad z0 or c0 also pushes the offset past size().
  4. If the image may have been resized, recompute the valid range from img.width() at call time instead of caching indices.

Example fix

// before
CImg<float> row = img.get_shared_points(0, img.width());   // width, not width-1
// after
if (x1 >= img.width()) x1 = img.width() - 1;
CImg<float> row = img.get_shared_points(0, x1, y, z, c);
Defensive patterns

Strategy: validation

Validate before calling

bool ok = x0 <= x1 && x1 < img.width() && y0 < img.height() && z0 < img.depth() && c0 < img.spectrum();

Try / catch

try { auto pts = img.get_shared_points(x0, x1, y, z, c); }
catch (CImgArgumentException& e) { /* clamp indices and retry or report range error */ }

Prevention

When it happens

Trigger: Calling img.get_shared_points(x0,x1,...) with x0 > x1, or with x1 (or x0) so large that offset(x1,y0,z0,c0) exceeds the total number of pixels, e.g. x1 >= img.width().

Common situations: Off-by-one errors where the caller passes a count instead of an inclusive last index (x1 = width instead of width-1); copying code between images of different sizes; a resized image making previously valid indices out of range.

Related errors


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

Appendix: source

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

        return (float)(*mp)(x,y,z,c);
      }
    };

    //! Return a shared-memory image referencing a range of pixels of the image instance.
    /**
       \param x0 X-coordinate of the starting pixel.
       \param x1 X-coordinate of the ending pixel.
       \param y0 Y-coordinate.
       \param z0 Z-coordinate.
       \param c0 C-coordinate.
     **/
    CImg<T> get_shared_points(const unsigned int x0, const unsigned int x1,
                              const unsigned int y0=0, const unsigned int z0=0, const unsigned int c0=0) {
      const ulongT
        beg = (ulongT)offset(x0,y0,z0,c0),
        end = (ulongT)offset(x1,y0,z0,c0);
      if (beg>end || beg>=size() || end>=size())
        throw CImgArgumentException(_cimg_instance
                                    "get_shared_points(): Invalid request of a shared-memory subset (%u->%u,%u,%u,%u).",
                                    cimg_instance,
                                    x0,x1,y0,z0,c0);
      return CImg<T>(_data + beg,x1 - x0 + 1,1,1,1,true);
    }

    //! Return a shared-memory image referencing a range of pixels of the image instance \const.
    const CImg<T> get_shared_points(const unsigned int x0, const unsigned int x1,
                                    const unsigned int y0=0, const unsigned int z0=0, const unsigned int c0=0) const {
      const ulongT
        beg = (ulongT)offset(x0,y0,z0,c0),
        end = (ulongT)offset(x1,y0,z0,c0);
      if (beg>end || beg>=size() || end>=size())
        throw CImgArgumentException(_cimg_instance
                                    "get_shared_points(): Invalid request of a shared-memory subset (%u->%u,%u,%u,%u).",
                                    cimg_instance,
                                    x0,x1,y0,z0,c0);
      return CImg<T>(_data + beg,x1 - x0 + 1,1,1,1,true);

View on GitHub (pinned to f788b534b4)