{"record":{"id":"2cad14ac2cc44bb1","repo":"Yalantis/uCrop","slug":"min-max-s","errorCode":null,"errorMessage":"min_max(): %s.","messagePattern":"min_max\\(\\): (.+?)\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":65630,"sourceCode":"      }\n      return *ptr_max;\n    }\n\n    //! Return a reference to the minimum pixel value of the instance list and return the maximum vvalue as well.\n    /**\n       \\param[out] max_val Value of the maximum value found.\n    **/\n    template<typename t>\n    T& min_max(t& max_val) {\n      bool is_all_empty = true;\n      T *ptr_min = 0;\n      cimglist_for(*this,l) if (!_data[l].is_empty()) {\n        ptr_min = _data[l]._data;\n        is_all_empty = false;\n        break;\n      }\n      if (is_all_empty)\n        throw CImgInstanceException(_cimglist_instance\n                                    \"min_max(): %s.\",\n                                    _data?\"List of empty images\":\"Empty instance\",\n                                    cimglist_instance);\n      T min_value = *ptr_min, max_value = min_value;\n      cimglist_for(*this,l) {\n        const CImg<T>& img = _data[l];\n        cimg_for(img,ptrs,T) {\n          const T val = *ptrs;\n          if (val<min_value) { min_value = val; ptr_min = ptrs; }\n          if (val>max_value) max_value = val;\n        }\n      }\n      max_val = (t)max_value;\n      return *ptr_min;\n    }\n\n    //! Return a reference to the minimum pixel value of the instance list and return the maximum vvalue as well \\const.\n    /**","sourceCodeStart":65612,"sourceCodeEnd":65648,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L65612-L65648","documentation":"CImgList<T>::min_max() computes both the minimum and maximum pixel values in one pass. It throws CImgInstanceException \"min_max(): %s.\" when the list is empty or all images within it are empty (ucrop/src/main/jni/CImg.h:65630), because neither extremum can be defined over zero pixels.","triggerScenarios":"Calling min_max() on a CImgList where the scan loop finds no non-empty image — e.g. default-constructed list, assign()-cleared list, or a list of images resized to zero dimensions.","commonSituations":"Range normalization (mapping values to [min,max]) after a decoding step produced nothing; histogram/contrast tools run on empty batches; buggy crop logic yielding 0x0 images.","solutions":["Pre-check that at least one image in the list is non-empty before calling min_max().","Fix upstream load/crop/resize so images have pixels; verify with !img.is_empty().","Catch CImgInstanceException and handle the no-data case (skip normalization, use defaults).","Restructure the pipeline so the statistics call only runs when the population stage reported success."],"exampleFix":"// before\nT mn, mx;\nlist.min_max(mn, mx);\n\n// after\nbool any = false;\nfor (unsigned int l = 0; l < list.size(); ++l) if (!list[l].is_empty()) { any = true; break; }\nif (!any) return;\nT mn, mx;\nlist.min_max(mn, mx);","handlingStrategy":"validation","validationCode":"bool any = false; for (unsigned int l = 0; l < list.size(); ++l) if (!list[l].is_empty()) { any = true; break; } if (!any) { /* skip min_max */ }","typeGuard":"static inline bool hasNonEmptyImage(const CImgList<T>& l) { cimglist_for(l, i) if (!l[i].is_empty()) return true; return false; }","tryCatchPattern":"try { list.min_max(mn, mx); } catch (CImgInstanceException& e) { mn = mx = defaultValue; }","preventionTips":["Pre-check non-emptiness before min_max()/normalization.","Confirm crop/resize operations never yield 0-size images.","Order the pipeline: load, verify, then compute statistics.","Catch CImgInstanceException at pipeline level as a safety net."],"tags":["cimg","jni","empty-instance","statistics"],"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"}