{"record":{"id":"f08db2b0481c0aef","repo":"Yalantis/uCrop","slug":"atx-empty-instance","errorCode":null,"errorMessage":"atX(): Empty instance.","messagePattern":"atX\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":15643,"sourceCode":"       Return a reference to the pixel value of the image instance located at (\\c x,\\c y,\\c z,\\c c),\n       or to the nearest pixel location in the image instance in case of out-of-bounds access along the X-axis.\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\n       - Similar to at(int,int,int,int,const T), except that an out-of-bounds access returns the value of the\n         nearest pixel in the image instance, regarding the specified X-coordinate.\n       - Due to the additional boundary checking operation, this method is slower than operator()(). Use it when\n         you are \\e not sure about the validity of the specified pixel coordinates.\n       - If you know your image instance is \\e not empty, you may rather use the slightly faster method\n         \\c _at(int,int,int,int).\n       \\warning\n       - There is \\e no boundary checking performed for the Y,Z and C-coordinates, so they must be inside image bounds.\n     **/\n    T& atX(const int x, const int y=0, const int z=0, const int c=0) {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"atX(): Empty instance.\",\n                                    cimg_instance);\n      return _atX(x,y,z,c);\n    }\n\n    T& _atX(const int x, const int y=0, const int z=0, const int c=0) {\n      return (*this)(x<0?0:(x>=width()?width() - 1:x),y,z,c);\n    }\n\n    //! Access to a pixel value, using Neumann boundary conditions for the X-coordinate \\const.\n    const T& atX(const int x, const int y=0, const int z=0, const int c=0) const {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"atX(): Empty instance.\",\n                                    cimg_instance);\n      return _atX(x,y,z,c);\n    }\n","sourceCodeStart":15625,"sourceCodeEnd":15661,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L15625-L15661","documentation":"CImg::atX(x,y,z,c) clamps only the X coordinate to image bounds (Y,Z,C are unchecked) but first requires a non-empty image. On an empty instance it throws CImgInstanceException because there are no valid coordinates to clamp to.","triggerScenarios":"Calling img.atX(x,y,z,c) on a default-constructed or zero-sized image.","commonSituations":"Downstream code reading pixels after a load failure left the image empty; conditional assignment path skipped; empty crop result passed on.","solutions":["Check img.is_empty() before calling atX().","Confirm the image-producing step (load/crop/assign) succeeded before pixel reads.","Remember Y,Z,C are unchecked - validate them yourself even on non-empty images."],"exampleFix":"// before\nfloat v = img.atX(x, y); // throws if img empty\n// after\nif (img && !img.is_empty()) { float v = img.atX(x, y); }","handlingStrategy":"validation","validationCode":"if (!img.is_empty() && y >= 0 && y < img.height() && z >= 0 && z < img.depth() && c >= 0 && c < img.spectrum()) {\n  T v = img.atX(x, y, z, c);\n}","typeGuard":null,"tryCatchPattern":"try {\n  T v = img.atX(x, y);\n} catch (CImgInstanceException& e) {\n  // empty image fallback\n}","preventionTips":["Check is_empty() before pixel sampling; atX only guards X.","Validate Y/Z/C manually - atX does not clamp them.","Ensure image-loading code paths always either succeed or abort early."],"tags":["cimg","empty-image","boundary-conditions","pixel-access"],"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"}