Yalantis/uCrop · error · CImgInstanceException
atNXY(): Empty instance.
Error message
atNXY(): Empty instance.
What it means
Non-const CImgList<T>::atNXY(pos,x,y,z=0,c=0) accesses a writable pixel with Neumann boundary conditions on coordinates (pos,x,y) (z and c default to 0). It throws CImgInstanceException when the list instance is empty.
Source
Thrown at ucrop/src/main/jni/CImg.h:65122
}
//! Access to pixel value with Dirichlet boundary conditions for the 3 coordinates (\c pos, \c x,\c y) \const.
T atNXY(const int pos, const int x, const int y, const int z, const int c, const T& out_value) const {
return (pos<0 || pos>=width())?out_value:_data[pos].atXY(x,y,z,c,out_value);
}
//! Access to pixel value with Neumann boundary conditions for the 3 coordinates (\c pos, \c x,\c y).
/**
\param pos Index of the image element to access.
\param x X-coordinate of the pixel value.
\param y Y-coordinate of the pixel value.
\param z Z-coordinate of the pixel value.
\param c C-coordinate of the pixel value.
\note <tt>list.atNXYZ(p,x,y,z,c);</tt> is equivalent to <tt>list[p].atXYZ(x,y,z,c);</tt>.
**/
T& atNXY(const int pos, const int x, const int y, const int z=0, const int c=0) {
if (is_empty())
throw CImgInstanceException(_cimglist_instance
"atNXY(): Empty instance.",
cimglist_instance);
return _atNXY(pos,x,y,z,c);
}
//! Access to pixel value with Neumann boundary conditions for the 3 coordinates (\c pos, \c x,\c y) \const.
T atNXY(const int pos, const int x, const int y, const int z=0, const int c=0) const {
if (is_empty())
throw CImgInstanceException(_cimglist_instance
"atNXY(): Empty instance.",
cimglist_instance);
return _atNXY(pos,x,y,z,c);
}
T& _atNXY(const int pos, const int x, const int y, const int z=0, const int c=0) {
return _data[cimg::cut(pos,0,width() - 1)].atXY(x,y,z,c);View on GitHub (pinned to f788b534b4)
Solutions
- Check list.is_empty() before any atNXY call.
- Confirm the list-populating call succeeded and returned a nonzero size.
- If editing a single image, extract it (or use a CImg directly) and check is_empty() on the image instead.
- Catch CImgInstanceException if empty lists are a normal input condition.
Example fix
// before CImgList<unsigned char> frames; frames.atNXY(0, x, y) = 255; // after CImgList<unsigned char> frames; if (!frames.load(path) || frames.is_empty()) return; frames.atNXY(0, x, y, 0, 0) = 255;
Defensive patterns
Strategy: validation
Validate before calling
// C++ if (list.is_empty()) return; // before atNXY writes
Type guard
template <typename T>
bool writable(const CImgList<T>& l) { return !l.is_empty(); } Try / catch
// C++
try {
list.atNXY(p, x, y) = v;
} catch (CImgInstanceException& e) {
// empty list: re-load or skip
} Prevention
- Check is_empty() before 2D pixel-edit loops on lists.
- Detect remove_image() calls that can empty the list mid-pipeline.
- Check load() results so emptiness is caught at the source.
- Prefer editing a CImg directly for single-image work.
When it happens
Trigger: Calling list.atNXY(p,x,y) on a CImgList with is_empty()==true, e.g. an unloaded or cleared list.
Common situations: 2D pixel edits on a list-based image set whose load failed; code after remove_image() removed all entries; lists returned empty by a filtering routine.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- atNXYZC(): Empty instance.
- atNXYZ(): Empty instance.
- atNX(): Empty instance.
- atN(): Empty instance.
- cimg::mod(): Specified modulo value is 0.
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/0438533431a84373.
Report an issue: GitHub.