{"record":{"id":"f69a3e67d21727a8","repo":"Yalantis/uCrop","slug":"atxyzc-empty-instance","errorCode":null,"errorMessage":"atXYZC(): Empty instance.","messagePattern":"atXYZC\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":15789,"sourceCode":"        (cimg::temporary(out_value)=out_value):(*this)(x,y,z,c);\n    }\n\n    //! Access to a pixel value, using Dirichlet boundary conditions \\const.\n    T atXYZC(const int x, const int y, const int z, const int c, const T& out_value) const {\n      return (x<0 || y<0 || z<0 || c<0 || x>=width() || y>=height() || z>=depth() || c>=spectrum())?out_value:\n        (*this)(x,y,z,c);\n    }\n\n    //! Access to a pixel value, using Neumann boundary conditions.\n    /**\n       Similar to atX(int,int,int,int), except that boundary checking is performed on all X,Y,Z and C-coordinates.\n       \\note\n       - If you know your image instance is \\e not empty, you may rather use the slightly faster method\n         \\c _atXYZC(int,int,int,int).\n    **/\n    T& atXYZC(const int x, const int y, const int z, const int c) {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"atXYZC(): Empty instance.\",\n                                    cimg_instance);\n      return _atXYZC(x,y,z,c);\n    }\n\n    T& _atXYZC(const int x, const int y, const int z, const int c) {\n      return (*this)(cimg::cut(x,0,width() - 1),\n                     cimg::cut(y,0,height() - 1),\n                     cimg::cut(z,0,depth() - 1),\n                     cimg::cut(c,0,spectrum() - 1));\n    }\n\n    //! Access to a pixel value, using Neumann boundary conditions \\const.\n    const T& atXYZC(const int x, const int y, const int z, const int c) const {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"atXYZC(): Empty instance.\",\n                                    cimg_instance);","sourceCodeStart":15771,"sourceCodeEnd":15807,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L15771-L15807","documentation":"CImg<T>::atXYZC(x,y,z,c) is a checked pixel accessor using Neumann boundary conditions for the X coordinate. The library throws CImgInstanceException when the image instance is empty (no pixel buffer allocated, e.g. width/height/depth/spectrum all 0), because there is no data to read from. The underscore-prefixed _atXYZC variant skips this check for performance. This overload is the non-const version returning a mutable reference.","triggerScenarios":"Calling img.atXYZC(x,y,z,c) on a CImg instance that was default-constructed, assigned from an empty image, or whose load failed (is_empty() == true, size() == 0).","commonSituations":"Default-constructed CImg never assigned; imread()/load() on a missing or corrupt file silently producing an empty image; an image constructed with 0 dimensions from computed width/height; passing an uninitialized member image in a class.","solutions":["Check img.is_empty() (or !img) before calling atXYZC and initialize or load the image first.","Verify the image was actually loaded: check the return value / file path of load()/imread().","Construct the image with explicit non-zero dimensions, e.g. CImg<T> img(w,h,d,s).","If emptiness is impossible, call the unchecked _atXYZC() for speed — but only after validating once."],"exampleFix":"// before\nCImg<unsigned char> img;\nfloat v = img.atXYZC(x, y, 0, 0);\n// after\nCImg<unsigned char> img(\"input.png\");\nif (!img.is_empty()) {\n  float v = img.atXYZC(x, y, 0, 0);\n}","handlingStrategy":"validation","validationCode":"if (img.is_empty()) { /* load/allocate or bail out */ } else { T& v = img.atXYZC(x,y,z,c); }","typeGuard":"inline bool usable(const cimg_library::CImg<T>& img) { return !img.is_empty(); }","tryCatchPattern":"try { auto& v = img.atXYZC(x,y,z,c); } catch (cimg_library::CImgInstanceException& e) { std::cerr << e.what() << '\\n'; /* load image and retry */ }","preventionTips":["Always check is_empty() after load()/imread().","Never keep default-constructed CImg members without an is_loaded flag.","Validate computed dimensions are > 0 before constructing images.","Use _atXYZC only behind a guaranteed non-empty precondition."],"tags":["cimg","image-processing","empty-instance","jni"],"backgroundTag":"empty-required-field","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"}