{"record":{"id":"06c1bd84a2cac5e2","repo":"Yalantis/uCrop","slug":"cimg-s-s-u-cubic-atxy-p-empty-instanc","errorCode":null,"errorMessage":"CImg<%s>::%s() [%u]: cubic_atXY_p(): Empty instance.","messagePattern":"CImg<(.+?)>::(.+?)\\(\\) \\[%u\\]: cubic_atXY_p\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":16494,"sourceCode":"    }\n\n    //! Return clamped pixel value, using cubic interpolation and Neumann boundary conditions for the X,Y-coordinates.\n    /**\n       Similar to cubic_atXY(float,float,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_atXY_c(const float fx, const float fy, const int z, const int c) const {\n      return cimg::type<T>::cut(cubic_atXY(fx,fy,z,c));\n    }\n\n    T _cubic_atXY_c(const float fx, const float fy, const int z, const int c) const {\n      return cimg::type<T>::cut(_cubic_atXY(fx,fy,z,c));\n    }\n\n    //! Return pixel value, using cubic interpolation and periodic boundary conditions for the X and Y-coordinates.\n    Tfloat cubic_atXY_p(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                                    \"cubic_atXY_p(): Empty instance.\",\n                                    cimg_instance);\n      return _cubic_atXY_p(fx,fy,z,c);\n    }\n\n    Tfloat _cubic_atXY_p(const float fx, const float fy, 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        nfy = cimg::type<float>::is_nan(fy)?0:cimg::mod(fy,_height - 0.5f);\n      const int x = (int)nfx, y = (int)nfy;\n      const float dx = nfx - x, dy = nfy - y;\n      const int\n        px = cimg::mod(x - 1,width()), nx = cimg::mod(x + 1,width()), ax = cimg::mod(x + 2,width()),\n        py = cimg::mod(y - 1,height()), ny = cimg::mod(y + 1,height()), ay = cimg::mod(y + 2,height());\n      const Tfloat\n        Ipp = (Tfloat)(*this)(px,py,z,c), Icp = (Tfloat)(*this)(x,py,z,c), Inp = (Tfloat)(*this)(nx,py,z,c),\n        Iap = (Tfloat)(*this)(ax,py,z,c),\n        Ip = Icp + 0.5f*(dx*(-Ipp + Inp) + dx*dx*(2*Ipp - 5*Icp + 4*Inp - Iap) + dx*dx*dx*(-Ipp + 3*Icp - 3*Inp + Iap)),","sourceCodeStart":16476,"sourceCodeEnd":16512,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L16476-L16512","documentation":"cubic_atXY_p() is the periodic-boundary bicubic interpolation accessor. It throws CImgInstanceException when is_empty() is true, i.e. the image instance holds no pixels, because periodic sampling still requires a non-empty buffer.","triggerScenarios":"Calling cubic_atXY_p(fx,fy,...) on an empty CImg (default-constructed, cleared, or failed load); tiling/seamless patterns generated from an image that never received data.","commonSituations":"Texture/tiling generation where the source load silently failed; unit tests constructing CImg without assign(); JNI crop code receiving zero-sized dimensions from the Java layer.","solutions":["Guard with if (!img.is_empty()) before periodic bicubic sampling.","Validate dimensions coming from the caller (Java/Kotlin side) are >0 before constructing/cropping.","Fail fast on load errors rather than continuing with an empty image.","Wrap in try/catch for CImgInstanceException to convert it into an app-level error."],"exampleFix":"// before\nCImg<float> img(0, 0);\nfloat v = img.cubic_atXY_p(3.4f, 2.2f); // throws\n// after\nCImg<float> img(0, 0);\nif (img.width() > 0 && img.height() > 0) {\n  float v = img.cubic_atXY_p(3.4f, 2.2f);\n}","handlingStrategy":"validation","validationCode":"if (img.width() == 0 || img.height() == 0) return fallback;\nfloat v = img.cubic_atXY_p(fx, fy, z, c);","typeGuard":"bool ready(const CImg<T>& im) { return !im.is_empty() && im.width() && im.height(); }","tryCatchPattern":"try {\n  float v = img.cubic_atXY_p(fx, fy);\n} catch (const CImgInstanceException& e) {\n  // report 'image not initialized' to caller\n}","preventionTips":["Validate user- or caller-supplied crop dimensions before assignment.","Check load success; empty images commonly come from failed loads.","Keep image ownership clear so images are not cleared while still in use.","Test tiling/periodic code paths with deliberately empty inputs to confirm guards."],"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"}