Yalantis/uCrop · error · CImgInstanceException
atNX(): Empty instance.
Error message
atNX(): Empty instance.
What it means
Non-const CImgList<T>::atNX(pos,x,y=0,z=0,c=0) returns a writable pixel reference with Neumann boundary conditions on coordinates (pos,x) (y,z,c default to 0). It throws CImgInstanceException when the list instance is empty.
Source
Thrown at ucrop/src/main/jni/CImg.h:65177
}
//! Access to pixel value with Dirichlet boundary conditions for the 2 coordinates (\c pos,\c x) \const.
T atNX(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].atX(x,y,z,c,out_value);
}
//! Access to pixel value with Neumann boundary conditions for the 2 coordinates (\c pos, \c x).
/**
\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& atNX(const int pos, const int x, const int y=0, const int z=0, const int c=0) {
if (is_empty())
throw CImgInstanceException(_cimglist_instance
"atNX(): Empty instance.",
cimglist_instance);
return _atNX(pos,x,y,z,c);
}
//! Access to pixel value with Neumann boundary conditions for the 2 coordinates (\c pos, \c x) \const.
T atNX(const int pos, const int x, const int y=0, const int z=0, const int c=0) const {
if (is_empty())
throw CImgInstanceException(_cimglist_instance
"atNX(): Empty instance.",
cimglist_instance);
return _atNX(pos,x,y,z,c);
}
T& _atNX(const int pos, const int x, const int y=0, const int z=0, const int c=0) {
return _data[cimg::cut(pos,0,width() - 1)].atX(x,y,z,c);View on GitHub (pinned to f788b534b4)
Solutions
- Check list.is_empty() before the write loop.
- Verify the list size matches expectations (e.g. >=1 image) before indexing.
- Populate or re-load the list if the earlier load failed silently.
- Catch CImgInstanceException around batch writes if input can legitimately be empty.
Example fix
// before
CImgList<T> list; // never filled
list.atNX(0, x) = value;
// after
if (list.size() > 0) {
list.atNX(0, x) = value;
} Defensive patterns
Strategy: validation
Validate before calling
// C++
if (list.size() > 0) { /* atNX write is safe */ } Type guard
template <typename T>
bool editable(const CImgList<T>& l) { return !l.is_empty(); } Try / catch
// C++
try {
list.atNX(p, x) = v;
} catch (CImgInstanceException& e) {
// empty list handling
} Prevention
- Validate list size before batch write loops.
- Re-check emptiness after any remove/clear operations in the pipeline.
- Ensure load failures propagate instead of leaving silent empty lists.
- Use debug asserts on size in row-processing helpers.
When it happens
Trigger: Calling list.atNX(p,x) to write a pixel on a CImgList whose is_empty() is true (no images ever inserted or all removed).
Common situations: Row-based pixel processing on lists that failed to populate; mutating code paths downstream of a conditional load; lists emptied by filters before the write loop.
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.
- atNXY(): 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/5f83611a7603403c.
Report an issue: GitHub.