{"record":{"id":"d2f2d034fe33523f","repo":"Yalantis/uCrop","slug":"linear-atxy-empty-instance","errorCode":null,"errorMessage":"linear_atXY(): Empty instance.","messagePattern":"linear_atXY\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":15936,"sourceCode":"        dx = fx - x,\n        dy = fy - y;\n      const Tfloat\n        Icc = (Tfloat)atXY(x,y,z,c,out_value),  Inc = (Tfloat)atXY(nx,y,z,c,out_value),\n        Icn = (Tfloat)atXY(x,ny,z,c,out_value), Inn = (Tfloat)atXY(nx,ny,z,c,out_value);\n      return Icc + (Inc - Icc + (Icc + Inn - Icn - Inc)*dy)*dx + (Icn - Icc)*dy;\n    }\n\n    //! Return pixel value, using linear interpolation and Neumann boundary conditions for the X and Y-coordinates.\n    /**\n       Similar to linear_atX(float,int,int,int) const, except that the linear interpolation and the boundary checking\n       are achieved both for X and Y-coordinates.\n       \\note\n       - If you know your image instance is \\e not empty, you may rather use the slightly faster method\n         \\c _linear_atXY(float,float,int,int).\n    **/\n    Tfloat linear_atXY(const float fx, const float fy, const int z=0, const int c=0) const {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"linear_atXY(): Empty instance.\",\n                                    cimg_instance);\n\n      return _linear_atXY(fx,fy,z,c);\n    }\n\n    Tfloat _linear_atXY(const float fx, const float fy, const int z=0, const int c=0) const {\n      const float\n        nfx = cimg::cut(fx,0.f,width() - 1.f),\n        nfy = cimg::cut(fy,0.f,height() - 1.f);\n      const unsigned int\n        x = (unsigned int)nfx,\n        y = (unsigned int)nfy;\n      const float\n        dx = nfx - x,\n        dy = nfy - y;\n      const unsigned int\n        nx = dx>0?x + 1:x,","sourceCodeStart":15918,"sourceCodeEnd":15954,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L15918-L15954","documentation":"CImg<T>::linear_atXY(fx,fy,z,c) returns a bilinearly interpolated pixel value with Neumann boundary conditions on X and Y. It throws CImgInstanceException when the image is empty, as no buffer exists for interpolation. Z and C are not bounds-checked here.","triggerScenarios":"Calling linear_atXY() on an empty CImg instance (default-constructed, failed load, zero-sized dimensions).","commonSituations":"Image registration or feature sampling code fed an unloaded image; reading from a video frame that was never captured; empty ROI extraction upstream.","solutions":["Guard with if (!img.is_empty()) before calling linear_atXY.","Check that load()/imread() produced a non-empty image (dimensions > 0).","Allocate the image explicitly with assign(w,h) when constructed by default.","Use _linear_atXY() in hot loops only after a single upfront emptiness check."],"exampleFix":"// before\nCImg<unsigned char> frame; // never filled\nfloat v = frame.linear_atXY(10.2f, 5.7f);\n// after\ncimg_for(img, ...) or:\nif (!frame.is_empty()) {\n  float v = frame.linear_atXY(10.2f, 5.7f);\n}","handlingStrategy":"validation","validationCode":"if (img.is_empty()) { img.assign(w, h); /* or load */ } float v = img.linear_atXY(fx, fy);","typeGuard":"inline bool ready(const cimg_library::CImg<T>& img) { return !img.is_empty(); }","tryCatchPattern":"try { float v = img.linear_atXY(fx, fy); } catch (cimg_library::CImgInstanceException& e) { std::cerr << e.what() << '\\n'; /* reload image */ }","preventionTips":["Check is_empty() after imread()/load().","Initialize images with assign(w,h) at declaration.","Validate video frames are captured before sampling.","Use _linear_atXY after a single entry-point emptiness check."],"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"}