Yalantis/uCrop · error · CImgInstanceException
atN(): Empty instance.
Error message
atN(): Empty instance.
What it means
Non-const CImgList<T>::atN(pos,x=0,y=0,z=0,c=0) accesses a writable pixel of the image at index pos, with all of x,y,z,c defaulting to 0 (Neumann boundary clamping on pos). It throws CImgInstanceException when the list instance is empty.
Source
Thrown at ucrop/src/main/jni/CImg.h:65232
}
//! Access to pixel value with Dirichlet boundary conditions for the coordinate (\c pos) \const.
T atN(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:(*this)(pos,x,y,z,c);
}
//! Return pixel value with Neumann boundary conditions for the coordinate (\c pos).
/**
\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& atN(const int pos, const int x=0, const int y=0, const int z=0, const int c=0) {
if (is_empty())
throw CImgInstanceException(_cimglist_instance
"atN(): Empty instance.",
cimglist_instance);
return _atN(pos,x,y,z,c);
}
//! Return pixel value with Neumann boundary conditions for the coordinate (\c pos) \const.
T atN(const int pos, const int x=0, const int y=0, const int z=0, const int c=0) const {
if (is_empty())
throw CImgInstanceException(_cimglist_instance
"atN(): Empty instance.",
cimglist_instance);
return _atN(pos,x,y,z,c);
}
T& _atN(const int pos, const int x=0, const int y=0, const int z=0, const int c=0) {
return _data[cimg::cut(pos,0,width() - 1)](x,y,z,c);
}
View on GitHub (pinned to f788b534b4)
Solutions
- Check list.is_empty() (or size()>0) before calling atN.
- Ensure the load/insert path succeeded before pixel access.
- If you only ever use one image, consider CImg<T> instead of CImgList and check the image is non-empty too.
- Wrap in try/catch on CImgInstanceException where emptiness is an expected input.
Example fix
// before
CImgList<T> list = load(path); // may leave list empty on failure
list.atN(0) = 0;
// after
CImgList<T> list;
list.load(path);
if (!list.is_empty()) {
list.atN(0) = 0;
} Defensive patterns
Strategy: validation
Validate before calling
// C++ if (list.is_empty()) return; // before list.atN(p)
Type guard
template <typename T>
bool usable(const CImgList<T>& l) { return l.size() > 0; } Try / catch
// C++
try {
list.atN(0) = 0;
} catch (CImgInstanceException& e) {
// list empty: load/reinit or skip
} Prevention
- Always verify the list is non-empty before atN pixel probes.
- Check load()/assign() outcomes at population time.
- Consider CImg<T> instead of a one-image CImgList to simplify emptiness handling.
- Note the convenience default args (x=y=z=c=0) hide that pos is the only required index; emptiness is still fatal.
When it happens
Trigger: Calling list.atN(p) (often effectively list.atN(0)) on an empty CImgList to read/write pixel (0,0,0,0) of image p.
Common situations: Quick pixel probes on lists that were never loaded; code assuming at least one image exists after processing; lists emptied by prior remove/clear calls.
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.
- atNX(): Empty instance.
- cimg::mod(): Specified modulo value is 0.
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/22e4e0a8f5278c91.
Report an issue: GitHub.