{"record":{"id":"5574ea32803f2313","repo":"Yalantis/uCrop","slug":"at-empty-instance","errorCode":null,"errorMessage":"at(): Empty instance.","messagePattern":"at\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":15572,"sourceCode":"    }\n\n    //! Access to a pixel value at a specified offset, using Neumann boundary conditions.\n    /**\n       Return a reference to the pixel value of the image instance located at a specified \\c offset,\n       or to the nearest pixel location in the image instance in case of out-of-bounds access.\n       \\param offset Offset to the desired pixel value.\n       \\note\n       - Similar to at(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 offset, i.e.\n         - If \\c offset<0, then \\c img[0] is returned.\n         - If \\c offset>=img.size(), then \\c img[img.size() - 1] is returned.\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 offset.\n       - If you know your image instance is \\e not empty, you may rather use the slightly faster method \\c _at(int).\n     **/\n    T& at(const int offset) {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"at(): Empty instance.\",\n                                    cimg_instance);\n      return _at(offset);\n    }\n\n    T& _at(const int offset) {\n      const unsigned int siz = (unsigned int)size();\n      return (*this)[offset<0?0:(unsigned int)offset>=siz?siz - 1:offset];\n    }\n\n    //! Access to a pixel value at a specified offset, using Neumann boundary conditions \\const.\n    const T& at(const int offset) const {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"at(): Empty instance.\",\n                                    cimg_instance);\n      return _at(offset);\n    }","sourceCodeStart":15554,"sourceCodeEnd":15590,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L15554-L15590","documentation":"CImg::at(offset) provides pixel access with Neumann boundary clamping on the offset, but first requires a non-empty image instance. If the image has no pixels (is_empty(), e.g. _data==null or size 0), it throws CImgInstanceException instead of returning a value.","triggerScenarios":"Calling img.at(offset) on an image constructed with CImg<T>() default constructor, or one whose width/height/depth/spectrum are all effectively zero.","commonSituations":"Image failed to load (empty result from load()) but code proceeds to read pixels; early return path left image un-assigned; crop/filter operation produced a 0-size image.","solutions":["Check img.is_empty() before calling at() and handle the empty case.","Verify the load/assign call that should populate the image succeeded (check return value / file existence).","Use at() only after successful initialization; for guaranteed non-empty code paths use the faster _at(offset)."],"exampleFix":"// before\nfloat v = img.at(idx); // throws if img empty\n// after\nif (!img.is_empty()) { float v = img.at(idx); } else { /* handle empty image */ }","handlingStrategy":"try-catch","validationCode":"if (img.is_empty()) { /* handle empty before calling at() */ }","typeGuard":null,"tryCatchPattern":"try {\n  T v = img.at(offset);\n} catch (CImgInstanceException& e) {\n  // image empty: fallback value or error path\n}","preventionTips":["Check is_empty() right after any load()/assign() before pixel access.","Propagate load failures instead of silently passing empty images on.","Use operator()/_at only on verified non-empty images for speed."],"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"}