{"record":{"id":"d987b6fd8336ce9d","repo":"Yalantis/uCrop","slug":"cimg-s-s-u-cubic-atx-p-empty-instance","errorCode":null,"errorMessage":"CImg<%s>::%s() [%u]: cubic_atX_p(): Empty instance.","messagePattern":"CImg<(.+?)>::(.+?)\\(\\) \\[%u\\]: cubic_atX_p\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":16373,"sourceCode":"    }\n\n    //! Return clamped pixel value, using cubic interpolation and Neumann boundary conditions for the X-coordinate.\n    /**\n       Similar to cubic_atX(float,int,int,int) const, except that the return value is clamped to stay in the\n       min/max range of the datatype \\c T.\n    **/\n    T cubic_atX_c(const float fx, const int y, const int z, const int c) const {\n      return cimg::type<T>::cut(cubic_atX(fx,y,z,c));\n    }\n\n    T _cubic_atX_c(const float fx, const int y, const int z, const int c) const {\n      return cimg::type<T>::cut(_cubic_atX(fx,y,z,c));\n    }\n\n    //! Return pixel value, using cubic interpolation and periodic boundary conditions for the X-coordinate.\n    Tfloat cubic_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                                    \"cubic_atX_p(): Empty instance.\",\n                                    cimg_instance);\n      return _cubic_atX_p(fx,y,z,c);\n    }\n\n    Tfloat _cubic_atX_p(const float fx, const int y=0, const int z=0, const int c=0) const {\n      const float\n        nfx = cimg::type<float>::is_nan(fx)?0:cimg::mod(fx,_width - 0.5f);\n      const int\n        x = (int)nfx;\n      const float\n        dx = nfx - x;\n      const int\n        px = cimg::mod(x - 1,width()), nx = cimg::mod(x + 1,width()), ax = cimg::mod(x + 2,width());\n      const Tfloat\n        Ip = (Tfloat)(*this)(px,y,z,c), Ic = (Tfloat)(*this)(x,y,z,c),\n        In = (Tfloat)(*this)(nx,y,z,c), Ia = (Tfloat)(*this)(ax,y,z,c);\n      return Ic + 0.5f*(dx*(-Ip + In) + dx*dx*(2*Ip - 5*Ic + 4*In - Ia) + dx*dx*dx*(-Ip + 3*Ic - 3*In + Ia));","sourceCodeStart":16355,"sourceCodeEnd":16391,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L16355-L16391","documentation":"cubic_atX_p() is the periodic-boundary variant of cubic X-axis cubic interpolation. Like cubic_atX(), it checks is_empty() first and throws CImgInstanceException when the image has no pixels, because interpolation is undefined on an empty buffer.","triggerScenarios":"Calling cubic_atX_p(fx,...) on a default-constructed CImg<T> or one with any zero dimension; passing an image whose load failed into periodic resampling/wrapping code.","commonSituations":"Seamless-tiling / periodic-wrapping image transforms where the source image never loaded; pipeline stages that clear() and re-assign images leaving a window where the image is empty.","solutions":["Guard with if (!img.is_empty()) before calling cubic_atX_p().","Validate the loaded image dimensions right after load/assign and bail out early if empty.","Make upstream crop/resize code guarantee at least 1x1x1x1 dimensions.","Catch CImgInstanceException around the call to fail gracefully."],"exampleFix":"// before\nCImg<unsigned char> img; // never loaded\nfloat v = img.cubic_atX_p(1.5f);\n// after\nif (img && !img.is_empty()) {\n  float v = img.cubic_atX_p(1.5f);\n}","handlingStrategy":"validation","validationCode":"if (img.is_empty()) return 0.f; // or handle\nfloat v = img.cubic_atX_p(fx, y, z, c);","typeGuard":"template <typename T> bool non_empty(const CImg<T>& im) { return !im.is_empty(); }","tryCatchPattern":"try {\n  float v = img.cubic_atX_p(fx);\n} catch (const CImgInstanceException& e) {\n  // substitute fallback value or propagate error\n}","preventionTips":["Validate image dimensions > 0 before any periodic sampling.","Check load() success before processing.","In pipelines, assert non-empty images at stage boundaries.","Avoid clear()-then-use patterns without reassignment in between."],"tags":["cimg","image-processing","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"}