{"record":{"id":"462d5041084b1ca3","repo":"Yalantis/uCrop","slug":"linear-atx-empty-instance","errorCode":null,"errorMessage":"linear_atX(): Empty instance.","messagePattern":"linear_atX\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":15863,"sourceCode":"    /**\n       Return a linearly-interpolated pixel value of the image instance located at (\\c fx,\\c y,\\c z,\\c c),\n       or the value of the nearest pixel location in the image instance in case of out-of-bounds access along\n       the X-axis.\n       \\param fx X-coordinate of the pixel value (float-valued).\n       \\param y Y-coordinate of the pixel value.\n       \\param z Z-coordinate of the pixel value.\n       \\param c C-coordinate of the pixel value.\n       \\note\n       - Similar to linear_atX(float,int,int,int,const T) const, except that an out-of-bounds access returns\n         the value of the nearest pixel in the image instance, regarding the specified X-coordinate.\n       - If you know your image instance is \\e not empty, you may rather use the slightly faster method\n         \\c _linear_atX(float,int,int,int).\n       \\warning\n       - There is \\e no boundary checking performed for the Y,Z and C-coordinates, so they must be inside image bounds.\n    **/\n    Tfloat linear_atX(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(): Empty instance.\",\n                                    cimg_instance);\n\n      return _linear_atX(fx,y,z,c);\n    }\n\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);","sourceCodeStart":15845,"sourceCodeEnd":15881,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L15845-L15881","documentation":"CImg<T>::linear_atX(fx,y,z,c) returns a bilinearly interpolated pixel value with Neumann boundary conditions on the X-coordinate. It throws CImgInstanceException when the image is empty, since interpolation requires an allocated pixel buffer. Y, Z and C coordinates are NOT bounds-checked, only emptiness is validated here.","triggerScenarios":"Calling linear_atX() on an empty CImg instance (default-constructed, failed load, or zero-sized).","commonSituations":"Resampling/warping code operating on an image that failed to load; a default-constructed member image; empty result of a crop/extract operation.","solutions":["Check img.is_empty() before calling linear_atX.","Verify the image load succeeded and dimensions are non-zero before interpolation.","Initialize the image with allocate()/assign(w,h,d,s) if it was default-constructed.","Use _linear_atX() only after validating non-emptiness elsewhere for performance."],"exampleFix":"// before\nCImg<float> img;\nfloat v = img.linear_atX(3.5f, y);\n// after\nif (!img.is_empty()) {\n  float v = img.linear_atX(3.5f, y);\n}","handlingStrategy":"validation","validationCode":"if (img.is_empty()) throw std::runtime_error(\"image not initialized\"); float v = img.linear_atX(fx, y);","typeGuard":"inline bool samplable(const cimg_library::CImg<T>& img) { return !img.is_empty(); }","tryCatchPattern":"try { float v = img.linear_atX(fx, y); } catch (cimg_library::CImgInstanceException& e) { std::cerr << e.what() << '\\n'; v = 0; }","preventionTips":["Ensure images are loaded before resampling code runs.","Check is_empty() once at function entry, then use _linear_atX in loops.","Validate image dimensions after every load.","Treat empty result of crop/extract as an error condition upstream."],"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"}