{"record":{"id":"159cd2e5540f15e4","repo":"Yalantis/uCrop","slug":"cimg-instance-min-empty-instance","errorCode":null,"errorMessage":"_cimg_instance \"min(): Empty instance.\"","messagePattern":"_cimg_instance \"min\\(\\): Empty instance\\.\"","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":31749,"sourceCode":"       \\param expression Math formula as a C-string.\n       \\note Replace each pixel value \\f$I_{(x,y,z,c)}\\f$ of the image instance by\n       \\f$\\mathrm{maxabs}(I_{(x,y,z,c)},\\mathrm{expr}_{(x,y,z,c)})\\f$.\n    **/\n    CImg<T>& maxabs(const char *const expression) {\n      return maxabs((+*this)._fill(expression,true,3,0,\"maxabs\",this,0));\n    }\n\n    //! Pointwise maxabs operator between an image and an expression \\newinstance.\n    CImg<Tfloat> get_maxabs(const char *const expression) const {\n      return CImg<Tfloat>(*this,false).maxabs(expression);\n    }\n\n    //! Return a reference to the minimum pixel value.\n    /**\n     **/\n    T& min() {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"min(): Empty instance.\",\n                                    cimg_instance);\n      T *ptr_min = _data;\n      T min_value = *ptr_min;\n      cimg_for(*this,ptrs,T) if (*ptrs<min_value) min_value = *(ptr_min=ptrs);\n      return *ptr_min;\n    }\n\n    //! Return a reference to the minimum pixel value \\const.\n    const T& min() const {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"min(): Empty instance.\",\n                                    cimg_instance);\n      const T *ptr_min = _data;\n      T min_value = *ptr_min;\n      cimg_for(*this,ptrs,T) if (*ptrs<min_value) min_value = *(ptr_min=ptrs);\n      return *ptr_min;","sourceCodeStart":31731,"sourceCodeEnd":31767,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L31731-L31767","documentation":"CImg<T>::min() returns a reference to the minimum pixel value, but this requires at least one pixel. Calling it on an empty instance (width/height/depth/spectrum of 0) would dereference null memory, so CImgInstanceException is thrown.","triggerScenarios":"Calling img.min() on a default-constructed CImg, an image assigned() to empty, or an image whose data failed to load.","commonSituations":"Reading an image file that failed to load silently; slicing/cropping that produced a 0-size result; running stats on an optional image that was never initialized.","solutions":["Check img.is_empty() (or img.size()>0) before calling min()","Fix the upstream load/crop that produced the empty image","Use the const-safe stats variants with an emptiness guard"],"exampleFix":"// before\nfloat v = img.min();\n// after\nif (!img.is_empty()) { float v = img.min(); } else { /* handle empty */ }","handlingStrategy":"validation","validationCode":"if (!img.is_empty()) { ... img.min() ... }","typeGuard":null,"tryCatchPattern":"try { T v = img.min(); } catch (const CImgInstanceException& e) { /* handle empty image */ }","preventionTips":["Check is_empty()/size() after every load or crop","Use CImg<T>::get_stats or min_max with guards on optional images","Fail fast with a clear log when an expected image is empty"],"tags":["cimg","empty-instance","image-processing"],"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"}