{"record":{"id":"0c4a13601142be08","repo":"Yalantis/uCrop","slug":"cimg-s-s-u-cubic-atx-empty-instance","errorCode":null,"errorMessage":"CImg<%s>::%s() [%u]: cubic_atX(): Empty instance.","messagePattern":"CImg<(.+?)>::(.+?)\\(\\) \\[%u\\]: cubic_atX\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":16336,"sourceCode":"    /**\n       Return a cubicly-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\n       along the X-axis. The cubic interpolation uses Hermite splines.\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 cubic_atX(float,int,int,int,const T) const, except that the returned pixel value is\n         approximated by a cubic interpolation along the X-axis.\n       - If you know your image instance is \\e not empty, you may rather use the slightly faster method\n         \\c _cubic_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 cubic_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                                    \"cubic_atX(): Empty instance.\",\n                                    cimg_instance);\n      return _cubic_atX(fx,y,z,c);\n    }\n\n    Tfloat _cubic_atX(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::cut(fx,0.f,width() - 1.f);\n      const int\n        x = (int)nfx;\n      const float\n        dx = nfx - x;\n      const int\n        px = x - 1<0?0:x - 1, nx = dx>0?x + 1:x, ax = x + 2>=width()?width() - 1:x + 2;\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":16318,"sourceCodeEnd":16354,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L16318-L16354","documentation":"CImg's cubic_atX() performs cubic interpolation along the X-axis of an image. Before doing so it checks is_empty(); if the image instance has zero width/height/depth/spectrum (never assigned or constructed empty), it throws CImgInstanceException. The library refuses to interpolate on an image with no pixel buffer.","triggerScenarios":"Calling cubic_atX(fx,...) on a CImg constructed with the default constructor or with zero-size dimensions (e.g. CImg<float> img; img.cubic_atX(2.5f)); also when an image became empty after a failed load or clear()/assign() call.","commonSituations":"An image failed to load from disk (load() returned an empty image) and cropping/resampling code proceeds anyway; a crop rect computed to zero size before passing the image to ucrop interpolation; uninitialized member images in a class.","solutions":["Verify the image is non-empty before interpolating: if (img.is_empty()) handle/abort before calling cubic_atX().","Check the return value of load()/assign() so a failed load doesn't leave an empty image flowing into interpolation.","Ensure the crop/resize code never produces zero-dimension images (clamp width/height to >=1).","Wrap the interpolation call in try/catch for CImgInstanceException as a last-resort guard."],"exampleFix":"// before\nCImg<float> img;\nfloat v = img.cubic_atX(2.5f, 0, 0, 0); // throws: empty instance\n// after\nCImg<float> img;\nimg.load(\"in.png\");\nif (!img.is_empty()) {\n  float v = img.cubic_atX(2.5f, 0, 0, 0);\n}","handlingStrategy":"validation","validationCode":"if (img.is_empty()) { /* handle: skip, use default, or report error */ return; }\nfloat v = img.cubic_atX(fx, y, z, c);","typeGuard":"bool usable(const CImg<T>& img) { return !img.is_empty() && img.width() > 0; }","tryCatchPattern":"try {\n  float v = img.cubic_atX(fx, y, z, c);\n} catch (const CImgInstanceException& e) {\n  // log e.what(); fall back to nearest-neighbor or abort the crop\n}","preventionTips":["Always check is_empty() (or operator bool) after load()/assign().","Never let failed loads flow into interpolation code; early-return on load errors.","Clamp crop/resize dimensions to at least 1 pixel.","Initialize member CImg images explicitly rather than relying on default construction."],"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"}