{"record":{"id":"b303ec29d0f6d521","repo":"Yalantis/uCrop","slug":"atxy-empty-instance","errorCode":null,"errorMessage":"atXY(): Empty instance.","messagePattern":"atXY\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":15688,"sourceCode":"    T& atXY(const int x, const int y, const int z, const int c, const T& out_value) {\n      return (x<0 || y<0 || x>=width() || y>=height())?(cimg::temporary(out_value)=out_value):(*this)(x,y,z,c);\n    }\n\n    //! Access to a pixel value, using Dirichlet boundary conditions for the X and Y coordinates \\const.\n    T atXY(const int x, const int y, const int z, const int c, const T& out_value) const {\n      return (x<0 || y<0 || x>=width() || y>=height())?out_value:(*this)(x,y,z,c);\n    }\n\n    //! Access to a pixel value, using Neumann boundary conditions for the X and Y-coordinates.\n    /**\n       Similar to atX(int,int,int,int), except that boundary checking is performed both on X and Y-coordinates.\n       \\note\n       - If you know your image instance is \\e not empty, you may rather use the slightly faster method\n         \\c _atXY(int,int,int,int).\n     **/\n    T& atXY(const int x, const int y, const int z=0, const int c=0) {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"atXY(): Empty instance.\",\n                                    cimg_instance);\n      return _atXY(x,y,z,c);\n    }\n\n    T& _atXY(const int x, const int y, const int z=0, const int c=0) {\n      return (*this)(cimg::cut(x,0,width() - 1),\n                     cimg::cut(y,0,height() - 1),z,c);\n    }\n\n    //! Access to a pixel value, using Neumann boundary conditions for the X and Y-coordinates \\const.\n    const T& atXY(const int x, const int y, const int z=0, const int c=0) const {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"atXY(): Empty instance.\",\n                                    cimg_instance);\n      return _atXY(x,y,z,c);\n    }","sourceCodeStart":15670,"sourceCodeEnd":15706,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L15670-L15706","documentation":"Reported by CImg<T>::atXY(int,int,int,int,const T&) when the instance has no pixels: the operator() lookup cannot be performed on an empty (unassigned or zero-size) image, and the Dirichlet out_value overload cannot substitute for a nonexistent pixel store.","triggerScenarios":"Calling img.atXY(x,y,z,c) on an image of size 0 (default-constructed, failed load, or empty crop).","commonSituations":"Sampling from an image that failed to decode; algorithm assuming a prior step always produced pixels.","solutions":["Check img.is_empty() before calling atXY().","Validate that the load/processing step populated the image (dimensions > 0).","Use _atXY() on paths where non-emptiness is already guaranteed."],"exampleFix":"// before\nfloat v = img.atXY(x, y); // throws if empty\n// after\nif (!img.is_empty()) { float v = img.atXY(x, y); } else { /* fallback */ }","handlingStrategy":"validation","validationCode":"if (img && !img.is_empty()) { T v = img.atXY(x, y); }","typeGuard":null,"tryCatchPattern":"try {\n  T v = img.atXY(x, y);\n} catch (CImgInstanceException& e) {\n  // empty image: return default or log\n}","preventionTips":["Check is_empty() after load/crop before sampling.","Remember atXY clamps only X and Y; validate other coordinates yourself.","Fail fast on load errors so empty images never reach sampling code."],"tags":["cimg","empty-image","bounds-check","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"}