{"record":{"id":"75e58bc8ffe9064a","repo":"Yalantis/uCrop","slug":"linear-atx-p-empty-instance","errorCode":null,"errorMessage":"linear_atX_p(): Empty instance.","messagePattern":"linear_atX_p\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":15887,"sourceCode":"\n    Tfloat _linear_atX(const float fx, const int y=0, const int z=0, const int c=0) const {\n      const float\n        nfx = cimg::cut(fx,0.f,width() - 1.f);\n      const unsigned int\n        x = (unsigned int)nfx;\n      const float\n        dx = nfx - x;\n      const unsigned int\n        nx = dx>0?x + 1:x;\n      const Tfloat\n        Ic = (Tfloat)(*this)(x,y,z,c), In = (Tfloat)(*this)(nx,y,z,c);\n      return Ic + dx*(In - Ic);\n    }\n\n    //! Return pixel value, using linear interpolation and periodic boundary conditions for the X-coordinate.\n    Tfloat linear_atX_p(const float fx, const int y=0, const int z=0, const int c=0) const {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"linear_atX_p(): Empty instance.\",\n                                    cimg_instance);\n\n      return _linear_atX_p(fx,y,z,c);\n    }\n\n    Tfloat _linear_atX_p(const float fx, const int y=0, const int z=0, const int c=0) const {\n      const float\n        nfx = cimg::mod(fx,_width - 0.5f);\n      const unsigned int\n        x = (unsigned int)nfx;\n      const float\n        dx = nfx - x;\n      const unsigned int\n        nx = cimg::mod(x + 1,_width);\n      const Tfloat\n        Ic = (Tfloat)(*this)(x,y,z,c), In = (Tfloat)(*this)(nx,y,z,c);\n      return Ic + dx*(In - Ic);","sourceCodeStart":15869,"sourceCodeEnd":15905,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L15869-L15905","documentation":"CImg<T>::linear_atX_p(fx,y,z,c) returns an interpolated pixel value with periodic (wrap-around) boundary conditions on the X-coordinate. It throws CImgInstanceException when the instance is empty because there is no pixel data to interpolate.","triggerScenarios":"Calling linear_atX_p() on an empty CImg (never assigned, failed load, zero dimensions).","commonSituations":"Periodic/tileable interpolation on an image whose load failed; unwrapping images in phase-processing pipelines where the source buffer was never filled.","solutions":["Validate img.is_empty() == false before the call.","Confirm the source image load/allocation succeeded upstream.","Assign real dimensions/data via assign(w,h,1,s) plus fill or load before interpolating.","Use the unchecked _linear_atX_p() only with a prior emptiness guarantee."],"exampleFix":"// before\nfloat v = img.linear_atX_p(fx);\n// after\nif (!img.is_empty()) {\n  float v = img.linear_atX_p(fx);\n}","handlingStrategy":"validation","validationCode":"if (!img.is_empty()) { float v = img.linear_atX_p(fx); }","typeGuard":"inline bool hasData(const cimg_library::CImg<T>& img) { return !img.is_empty(); }","tryCatchPattern":"try { float v = img.linear_atX_p(fx); } catch (cimg_library::CImgInstanceException& e) { std::cerr << e.what() << '\\n'; }","preventionTips":["Load or assign data before periodic interpolation.","Assert non-empty invariants with cimg_assert or your own checks.","Check load success right after file I/O.","Do not pass default-constructed images to sampling helpers."],"tags":["cimg","interpolation","empty-instance"],"backgroundTag":"empty-required-field","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"}