{"record":{"id":"9ad31c11c7e9dc07","repo":"Yalantis/uCrop","slug":"max-s","errorCode":null,"errorMessage":"max(): %s.","messagePattern":"max\\(\\): (.+?)\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":65582,"sourceCode":"        const CImg<T>& img = _data[l];\n        cimg_for(img,ptrs,T) if (*ptrs<min_value) min_value = *(ptr_min=ptrs);\n      }\n      return *ptr_min;\n    }\n\n    //! Return a reference to the maximum pixel value of the instance list.\n    /**\n    **/\n    T& max() {\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(): %s.\",\n                                    _data?\"List of empty images\":\"Empty instance\",\n                                    cimglist_instance);\n      T max_value = *ptr_max;\n      cimglist_for(*this,l) {\n        const CImg<T>& img = _data[l];\n        cimg_for(img,ptrs,T) if (*ptrs>max_value) max_value = *(ptr_max=ptrs);\n      }\n      return *ptr_max;\n    }\n\n    //! Return a reference to the maximum pixel value of the instance list \\const.\n    const T& max() const {\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;","sourceCodeStart":65564,"sourceCodeEnd":65600,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L65564-L65600","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check for at least one non-empty image in the list before calling max().","Fix the load/crop/resize step that produced only empty images.","Catch CImgInstanceException and fall back to a default maximum or skip processing.","Add an early return on is_empty() (plus per-image emptiness) in analysis wrappers."],"exampleFix":"// before\nconst T mx = list.max();\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;\nconst T mx = list.max();","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 */ }","typeGuard":"static inline bool hasNonEmptyImage(const CImgList<T>& l) { cimglist_for(l, i) if (!l[i].is_empty()) return true; return false; }","tryCatchPattern":"try { mx = list.max(); } catch (CImgInstanceException& e) { mx = defaultValue; }","preventionTips":["Check for non-empty images before computing extrema.","Detect failed loads (zero-sized images) immediately after loading.","Avoid reusing list objects after assign() without repopulating them.","Centralize the emptiness guard in one shared utility."],"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"}