Yalantis/uCrop · error · CImgInstanceException
_cimg_instance "min_max(): Empty instance."
Error message
_cimg_instance "min_max(): Empty instance."
What it means
Instance guard in CImg<T>::min_max(t&): computing both minimum and maximum requires at least one pixel; the image is empty, so neither value exists. Same sentinel check used throughout the statistics methods.
Solutions
- Check is_empty() / size()>0 before calling min_max()
- Confirm the image load or data assignment succeeded
- Fix zero-size ROI/crop inputs
- Catch CImgInstanceException if the empty case must be tolerated
Example fix
// before
T maxv;
const T& minv = img.min_max(maxv);
// after
if (!img.is_empty()) {
T maxv;
const T& minv = img.min_max(maxv);
} Defensive patterns
Strategy: validation
Validate before calling
if (img.is_empty()) throw std::runtime_error("image empty before min_max()"); Type guard
bool usable = !img.is_empty() && img.size() > 0;
Try / catch
try { T maxv; const T& minv = img.min_max(maxv); } catch (const CImgInstanceException& e) { /* handle empty */ } Prevention
- Check is_empty() before min/max normalization
- Validate images right after load
- Fix ROI math to never produce zero-size crops
When it happens
Trigger: Calling CImg<T>::min_max(t& max_val) on an instance where is_empty() is true — no pixels allocated or dimensions set to zero.
Common situations: Normalizing or rescaling an image that failed to load; computing min/max for auto-contrast on an empty buffer; passing a default-constructed CImg into a statistics routine.
Related errors
- _cimg_instance "kth_smallest(): Empty instance."
- _cimg_instance "max_min(): Empty instance."
- _cimg_instance "maxabs(): Empty instance."
- _cimg_instance "median(): Empty instance."
- _cimg_instance "variance_mean(): Empty instance."
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/403013530795b405.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:31867
"maxabs(): Empty instance.",
cimg_instance);
const T *ptr_maxabs = _data;
T maxabs_value = *ptr_maxabs;
cimg_for(*this,ptrs,T) {
const T ma = cimg::abs(*ptrs);
if (ma>maxabs_value) { maxabs_value = ma; ptr_maxabs = ptrs; }
}
return *ptr_maxabs;
}
//! Return a reference to the minimum pixel value as well as the maximum pixel value.
/**
\param[out] max_val Maximum pixel value.
**/
template<typename t>
T& min_max(t& max_val) {
if (is_empty())
throw CImgInstanceException(_cimg_instance
"min_max(): Empty instance.",
cimg_instance);
const T *ptr_min, *ptr_max;
_min_max(ptr_min,ptr_max);
max_val = (t)*ptr_max;
return (T&)*ptr_min;
}
void _min_max(const T* &ptr_min, const T* &ptr_max) const {
T val_min = *_data, val_max = val_min;
ptr_min = ptr_max = _data;
if (cimg_use_openmp && size()>(1LU<<24)*cimg_openmp_sizefactor) {
#if cimg_use_openmp
cimg_pragma_openmp(parallel) {
T l_val_min = *_data, l_val_max = l_val_min;
const T *l_ptr_min = _data, *l_ptr_max = l_ptr_min;
cimg_pragma_openmp(for)
cimg_rofoff(*this,off) {View on GitHub (pinned to f788b534b4)