Yalantis/uCrop · error · CImgInstanceException
_cimg_instance "max(): Empty instance."
Error message
_cimg_instance "max(): Empty instance."
What it means
Instance guard in CImg<T>::max(): the method must return a reference to the largest pixel, but the image is empty (no pixels allocated), so no maximum exists to reference. It is the standard empty-instance check shared by the min/max family.
Solutions
- Check img.is_empty() (or img.size()>0) before calling max()
- Fix the load/crop logic that yielded an empty image
Example fix
// before
float v = img.max();
// after
if (!img.is_empty()) { float v = img.max(); } else { /* handle empty */ } Defensive patterns
Strategy: validation
Validate before calling
if (!img.is_empty()) { ... img.max() ... } Try / catch
try { T v = img.max(); } catch (const CImgInstanceException& e) { /* handle empty image */ } Prevention
- Check load return state and is_empty() before normalization code
- Avoid default-constructed images flowing into stats without guards
When it happens
Trigger: Calling img.max() on a default-constructed CImg or an image that became empty after assignment/crop/failed load.
Common situations: Computing normalization ranges on images that failed to load; optional overlay images never initialized; ROI cropping with empty intersection.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- atXYZC(): Empty instance.
- _cimg_instance "min(): Empty instance."
- _cimg_instance "minabs(): Empty instance."
- CImg< >:: () [%u]: cubic_atX(): Empty instance.
- CImg< >:: () [%u]: cubic_atX_p(): Empty instance.
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/16eb408bc4479bf1.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:31807
if (is_empty())
throw CImgInstanceException(_cimg_instance
"minabs(): Empty instance.",
cimg_instance);
const T *ptr_minabs = _data;
T minabs_value = *ptr_minabs;
cimg_for(*this,ptrs,T) {
const T ma = cimg::abs(*ptrs);
if (ma<minabs_value) { minabs_value = ma; ptr_minabs = ptrs; }
}
return *ptr_minabs;
}
//! Return a reference to the maximum pixel value.
/**
**/
T& max() {
if (is_empty())
throw CImgInstanceException(_cimg_instance
"max(): Empty instance.",
cimg_instance);
T *ptr_max = _data;
T max_value = *ptr_max;
cimg_for(*this,ptrs,T) if (*ptrs>max_value) max_value = *(ptr_max=ptrs);
return *ptr_max;
}
//! Return a reference to the maximum pixel value \const.
const T& max() const {
if (is_empty())
throw CImgInstanceException(_cimg_instance
"max(): Empty instance.",
cimg_instance);
const T *ptr_max = _data;
T max_value = *ptr_max;
cimg_for(*this,ptrs,T) if (*ptrs>max_value) max_value = *(ptr_max=ptrs);
return *ptr_max;View on GitHub (pinned to f788b534b4)