Yalantis/uCrop · error · CImgInstanceException

max_min(): %s.

Error message

max_min(): %s.

What it means

CImgList<T>::max_min() computes the maximum first and then the minimum pixel value. It throws CImgInstanceException "max_min(): %s." when the list contains no pixel data — null _data or all images empty (ucrop/src/main/jni/CImg.h:65692) — since neither extremum can be computed over zero pixels.

Source

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

      max_val = (t)max_value;
      return *ptr_min;
    }

    //! Return a reference to the minimum pixel value of the instance list and return the minimum value as well.
    /**
       \param[out] min_val Value of the minimum value found.
    **/
    template<typename t>
    T& max_min(t& min_val) {
      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_min(): %s.",
                                    _data?"List of empty images":"Empty instance",
                                    cimglist_instance);
      T min_value = *ptr_max, max_value = min_value;
      cimglist_for(*this,l) {
        const CImg<T>& img = _data[l];
        cimg_for(img,ptrs,T) {
          const T val = *ptrs;
          if (val>max_value) { max_value = val; ptr_max = ptrs; }
          if (val<min_value) min_value = val;
        }
      }
      min_val = (t)min_value;
      return *ptr_max;
    }

    //! Return a reference to the minimum pixel value of the instance list and return the minimum value as well \const.
    template<typename t>

View on GitHub (pinned to f788b534b4)

Solutions

  1. Verify at least one list element is non-empty before calling max_min().
  2. Fix the image load/assign stage so the list actually contains pixel data.
  3. Handle via try/catch on CImgInstanceException with a default or skip behavior.
  4. Early-exit analysis functions when the input list has no usable images.

Example fix

// before
T mx, mn;
list.max_min(mx, mn);

// after
bool any = false;
for (unsigned int l = 0; l < list.size(); ++l) if (!list[l].is_empty()) { any = true; break; }
if (!any) return;
T mx, mn;
list.max_min(mx, mn);
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 max_min */ }

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 { list.max_min(mx, mn); } catch (CImgInstanceException& e) { mx = mn = defaultValue; }

Prevention

When it happens

Trigger: Calling max_min() on a default-constructed or cleared CImgList, or on a list whose every image was resized/assigned to zero dimensions so the ptr_max scan finds nothing.

Common situations: Range computations on batches where all loads failed; contrast analysis on empty crops; statistics utilities invoked on accumulator lists that were never filled.

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/969dad9d5bfc4bff. Report an issue: GitHub.