{"record":{"id":"5f83611a7603403c","repo":"Yalantis/uCrop","slug":"atnx-empty-instance","errorCode":null,"errorMessage":"atNX(): Empty instance.","messagePattern":"atNX\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":65177,"sourceCode":"    }\n\n    //! Access to pixel value with Dirichlet boundary conditions for the 2 coordinates (\\c pos,\\c x) \\const.\n    T atNX(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:_data[pos].atX(x,y,z,c,out_value);\n    }\n\n    //! Access to pixel value with Neumann boundary conditions for the 2 coordinates (\\c pos, \\c x).\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& atNX(const int pos, const int x, const int y=0, const int z=0, const int c=0) {\n      if (is_empty())\n        throw CImgInstanceException(_cimglist_instance\n                                    \"atNX(): Empty instance.\",\n                                    cimglist_instance);\n\n      return _atNX(pos,x,y,z,c);\n    }\n\n    //! Access to pixel value with Neumann boundary conditions for the 2 coordinates (\\c pos, \\c x) \\const.\n    T atNX(const int pos, const int x, const int y=0, const int z=0, const int c=0) const {\n      if (is_empty())\n        throw CImgInstanceException(_cimglist_instance\n                                    \"atNX(): Empty instance.\",\n                                    cimglist_instance);\n\n      return _atNX(pos,x,y,z,c);\n    }\n\n    T& _atNX(const int pos, const int x, const int y=0, const int z=0, const int c=0) {\n      return _data[cimg::cut(pos,0,width() - 1)].atX(x,y,z,c);","sourceCodeStart":65159,"sourceCodeEnd":65195,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L65159-L65195","documentation":"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.","triggerScenarios":"Calling list.atNX(p,x) to write a pixel on a CImgList whose is_empty() is true (no images ever inserted or all removed).","commonSituations":"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.","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."],"exampleFix":"// before\nCImgList<T> list; // never filled\nlist.atNX(0, x) = value;\n// after\nif (list.size() > 0) {\n  list.atNX(0, x) = value;\n}","handlingStrategy":"validation","validationCode":"// C++\nif (list.size() > 0) { /* atNX write is safe */ }","typeGuard":"template <typename T>\nbool editable(const CImgList<T>& l) { return !l.is_empty(); }","tryCatchPattern":"// C++\ntry {\n  list.atNX(p, x) = v;\n} catch (CImgInstanceException& e) {\n  // empty list handling\n}","preventionTips":["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."],"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"}