{"record":{"id":"22e4e0a8f5278c91","repo":"Yalantis/uCrop","slug":"atn-empty-instance","errorCode":null,"errorMessage":"atN(): Empty instance.","messagePattern":"atN\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":65232,"sourceCode":"    }\n\n    //! Access to pixel value with Dirichlet boundary conditions for the coordinate (\\c pos) \\const.\n    T atN(const int pos, const int x, const int y, const int z, const int c, const T& out_value) const {\n      return (pos<0 || pos>=width())?out_value:(*this)(pos,x,y,z,c);\n    }\n\n    //! Return pixel value with Neumann boundary conditions for the coordinate (\\c pos).\n    /**\n       \\param pos Index of the image element to access.\n       \\param x X-coordinate of the pixel value.\n       \\param y Y-coordinate of the pixel value.\n       \\param z Z-coordinate of the pixel value.\n       \\param c C-coordinate of the pixel value.\n       \\note <tt>list.atNXYZ(p,x,y,z,c);</tt> is equivalent to <tt>list[p].atXYZ(x,y,z,c);</tt>.\n    **/\n    T& atN(const int pos, const int x=0, const int y=0, const int z=0, const int c=0) {\n      if (is_empty())\n        throw CImgInstanceException(_cimglist_instance\n                                    \"atN(): Empty instance.\",\n                                    cimglist_instance);\n      return _atN(pos,x,y,z,c);\n    }\n\n    //! Return pixel value with Neumann boundary conditions for the coordinate (\\c pos) \\const.\n    T atN(const int pos, const int x=0, const int y=0, const int z=0, const int c=0) const {\n      if (is_empty())\n        throw CImgInstanceException(_cimglist_instance\n                                    \"atN(): Empty instance.\",\n                                    cimglist_instance);\n      return _atN(pos,x,y,z,c);\n    }\n\n    T& _atN(const int pos, const int x=0, const int y=0, const int z=0, const int c=0) {\n      return _data[cimg::cut(pos,0,width() - 1)](x,y,z,c);\n    }\n","sourceCodeStart":65214,"sourceCodeEnd":65250,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L65214-L65250","documentation":"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.","triggerScenarios":"Calling list.atN(p) (often effectively list.atN(0)) on an empty CImgList to read/write pixel (0,0,0,0) of image p.","commonSituations":"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.","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."],"exampleFix":"// before\nCImgList<T> list = load(path); // may leave list empty on failure\nlist.atN(0) = 0;\n// after\nCImgList<T> list;\nlist.load(path);\nif (!list.is_empty()) {\n  list.atN(0) = 0;\n}","handlingStrategy":"validation","validationCode":"// C++\nif (list.is_empty()) return; // before list.atN(p)","typeGuard":"template <typename T>\nbool usable(const CImgList<T>& l) { return l.size() > 0; }","tryCatchPattern":"// C++\ntry {\n  list.atN(0) = 0;\n} catch (CImgInstanceException& e) {\n  // list empty: load/reinit or skip\n}","preventionTips":["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."],"tags":["cimg","cpp","empty-list","pixel-access"],"backgroundTag":"empty-result-set","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}