Yalantis/uCrop · error · CImgInstanceException

max(): %s.

Error message

max(): %s.

What it means

CImgList<T>::max() computes the maximum pixel value across the list. When no non-empty image exists (null _data or all elements empty), the library throws CImgInstanceException "max(): %s." with "List of empty images" or "Empty instance" (ucrop/src/main/jni/CImg.h:65582). Max is undefined without data, so the precondition check fires.

Source

Thrown at ucrop/src/main/jni/CImg.h:65582

        const CImg<T>& img = _data[l];
        cimg_for(img,ptrs,T) if (*ptrs<min_value) min_value = *(ptr_min=ptrs);
      }
      return *ptr_min;
    }

    //! Return a reference to the maximum pixel value of the instance list.
    /**
    **/
    T& max() {
      bool is_all_empty = true;
      T *ptr_max = 0;
      cimglist_for(*this,l) if (!_data[l].is_empty()) {
        ptr_max = _data[l]._data;
        is_all_empty = false;
        break;
      }
      if (is_all_empty)
        throw CImgInstanceException(_cimglist_instance
                                    "max(): %s.",
                                    _data?"List of empty images":"Empty instance",
                                    cimglist_instance);
      T max_value = *ptr_max;
      cimglist_for(*this,l) {
        const CImg<T>& img = _data[l];
        cimg_for(img,ptrs,T) if (*ptrs>max_value) max_value = *(ptr_max=ptrs);
      }
      return *ptr_max;
    }

    //! Return a reference to the maximum pixel value of the instance list \const.
    const T& max() const {
      bool is_all_empty = true;
      T *ptr_max = 0;
      cimglist_for(*this,l) if (!_data[l].is_empty()) {
        ptr_max = _data[l]._data;
        is_all_empty = false;

View on GitHub (pinned to f788b534b4)

Solutions

  1. Check for at least one non-empty image in the list before calling max().
  2. Fix the load/crop/resize step that produced only empty images.
  3. Catch CImgInstanceException and fall back to a default maximum or skip processing.
  4. Add an early return on is_empty() (plus per-image emptiness) in analysis wrappers.

Example fix

// before
const T mx = list.max();

// after
bool any = false;
for (unsigned int l = 0; l < list.size(); ++l) if (!list[l].is_empty()) { any = true; break; }
if (!any) return;
const T mx = list.max();
Defensive patterns

Strategy: validation

Validate before calling

bool any = false; for (unsigned int l = 0; l < list.size(); ++l) if (!list[l].is_empty()) { any = true; break; } if (!any) { /* skip */ }

Type guard

static inline bool hasNonEmptyImage(const CImgList<T>& l) { cimglist_for(l, i) if (!l[i].is_empty()) return true; return false; }

Try / catch

try { mx = list.max(); } catch (CImgInstanceException& e) { mx = defaultValue; }

Prevention

When it happens

Trigger: Calling max() (this overload) on a default-constructed CImgList or one whose images were all cleared/resized to zero, so the cimglist_for scan leaves ptr_max unset and is_all_empty true.

Common situations: Normalizing images by their global max after a failed load batch; computing contrast metrics on zero-sized crops; reusing a list object after assign() emptied it.

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


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/9ad31c11c7e9dc07. Report an issue: GitHub.