{"record":{"id":"403013530795b405","repo":"Yalantis/uCrop","slug":"cimg-instance-min-max-empty-instance","errorCode":null,"errorMessage":"_cimg_instance \"min_max(): Empty instance.\"","messagePattern":"_cimg_instance \"min_max\\(\\): Empty instance\\.\"","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":31867,"sourceCode":"                                    \"maxabs(): Empty instance.\",\n                                    cimg_instance);\n      const T *ptr_maxabs = _data;\n      T maxabs_value = *ptr_maxabs;\n      cimg_for(*this,ptrs,T) {\n        const T ma = cimg::abs(*ptrs);\n        if (ma>maxabs_value) { maxabs_value = ma; ptr_maxabs = ptrs; }\n      }\n      return *ptr_maxabs;\n    }\n\n    //! Return a reference to the minimum pixel value as well as the maximum pixel value.\n    /**\n       \\param[out] max_val Maximum pixel value.\n    **/\n    template<typename t>\n    T& min_max(t& max_val) {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"min_max(): Empty instance.\",\n                                    cimg_instance);\n      const T *ptr_min, *ptr_max;\n      _min_max(ptr_min,ptr_max);\n      max_val = (t)*ptr_max;\n      return (T&)*ptr_min;\n    }\n\n    void _min_max(const T* &ptr_min, const T* &ptr_max) const {\n      T val_min = *_data, val_max = val_min;\n      ptr_min = ptr_max = _data;\n      if (cimg_use_openmp && size()>(1LU<<24)*cimg_openmp_sizefactor) {\n#if cimg_use_openmp\n        cimg_pragma_openmp(parallel) {\n          T l_val_min = *_data, l_val_max = l_val_min;\n          const T *l_ptr_min = _data, *l_ptr_max = l_ptr_min;\n          cimg_pragma_openmp(for)\n          cimg_rofoff(*this,off) {","sourceCodeStart":31849,"sourceCodeEnd":31885,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L31849-L31885","documentation":"Instance guard in CImg<T>::min_max(t&): computing both minimum and maximum requires at least one pixel; the image is empty, so neither value exists. Same sentinel check used throughout the statistics methods.","triggerScenarios":"Calling CImg<T>::min_max(t& max_val) on an instance where is_empty() is true — no pixels allocated or dimensions set to zero.","commonSituations":"Normalizing or rescaling an image that failed to load; computing min/max for auto-contrast on an empty buffer; passing a default-constructed CImg into a statistics routine.","solutions":["Check is_empty() / size()>0 before calling min_max()","Confirm the image load or data assignment succeeded","Fix zero-size ROI/crop inputs","Catch CImgInstanceException if the empty case must be tolerated"],"exampleFix":"// before\nT maxv;\nconst T& minv = img.min_max(maxv);\n// after\nif (!img.is_empty()) {\n  T maxv;\n  const T& minv = img.min_max(maxv);\n}","handlingStrategy":"validation","validationCode":"if (img.is_empty()) throw std::runtime_error(\"image empty before min_max()\");","typeGuard":"bool usable = !img.is_empty() && img.size() > 0;","tryCatchPattern":"try { T maxv; const T& minv = img.min_max(maxv); } catch (const CImgInstanceException& e) { /* handle empty */ }","preventionTips":["Check is_empty() before min/max normalization","Validate images right after load","Fix ROI math to never produce zero-size crops"],"tags":["cimg","image-processing","empty-image"],"backgroundTag":"empty-image-instance","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}