{"record":{"id":"969dad9d5bfc4bff","repo":"Yalantis/uCrop","slug":"max-min-s","errorCode":null,"errorMessage":"max_min(): %s.","messagePattern":"max_min\\(\\): (.+?)\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":65692,"sourceCode":"      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 minimum value as well.\n    /**\n       \\param[out] min_val Value of the minimum value found.\n    **/\n    template<typename t>\n    T& max_min(t& min_val) {\n      bool is_all_empty = true;\n      T *ptr_max = 0;\n      cimglist_for(*this,l) if (!_data[l].is_empty()) {\n        ptr_max = _data[l]._data;\n        is_all_empty = false;\n        break;\n      }\n      if (is_all_empty)\n        throw CImgInstanceException(_cimglist_instance\n                                    \"max_min(): %s.\",\n                                    _data?\"List of empty images\":\"Empty instance\",\n                                    cimglist_instance);\n      T min_value = *ptr_max, 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>max_value) { max_value = val; ptr_max = ptrs; }\n          if (val<min_value) min_value = val;\n        }\n      }\n      min_val = (t)min_value;\n      return *ptr_max;\n    }\n\n    //! Return a reference to the minimum pixel value of the instance list and return the minimum value as well \\const.\n    template<typename t>","sourceCodeStart":65674,"sourceCodeEnd":65710,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L65674-L65710","documentation":"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.","triggerScenarios":"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.","commonSituations":"Range computations on batches where all loads failed; contrast analysis on empty crops; statistics utilities invoked on accumulator lists that were never filled.","solutions":["Verify at least one list element is non-empty before calling max_min().","Fix the image load/assign stage so the list actually contains pixel data.","Handle via try/catch on CImgInstanceException with a default or skip behavior.","Early-exit analysis functions when the input list has no usable images."],"exampleFix":"// before\nT mx, mn;\nlist.max_min(mx, mn);\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 mx, mn;\nlist.max_min(mx, mn);","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 max_min */ }","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.max_min(mx, mn); } catch (CImgInstanceException& e) { mx = mn = defaultValue; }","preventionTips":["Guard max_min() exactly like min()/max().","Verify the list contains pixel data after every mutation stage.","Fail fast at load time so empty data never reaches statistics.","Share one emptiness-check utility across the codebase."],"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"}