{"record":{"id":"0c5c9c7a266fa98b","repo":"Yalantis/uCrop","slug":"warp-instance-and-specified-relative-warping-fi","errorCode":null,"errorMessage":"warp(): Instance and specified relative warping field (%u,%u,%u,%u,%p) have different XYZ dimensions.","messagePattern":"warp\\(\\): Instance and specified relative warping field \\(%u,%u,%u,%u,%p\\) have different XYZ dimensions\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":40063,"sourceCode":"    /**\n       \\param warp Warping field.\n       \\param mode Can be { 0=backward-absolute | 1=backward-relative | 2=forward-absolute | 3=foward-relative }\n       \\param interpolation Can be <tt>{ 0=nearest | 1=linear | 2=cubic }</tt>.\n       \\param boundary_conditions Boundary conditions <tt>{ 0=dirichlet | 1=neumann | 2=periodic | 3=mirror }</tt>.\n    **/\n    template<typename t>\n    CImg<T>& warp(const CImg<t>& p_warp, const unsigned int mode=0,\n                  const unsigned int interpolation=1, const unsigned int boundary_conditions=0) {\n      return get_warp(p_warp,mode,interpolation,boundary_conditions).move_to(*this);\n    }\n\n    //! Warp image content by a warping field \\newinstance.\n    template<typename t>\n    CImg<T> get_warp(const CImg<t>& p_warp, const unsigned int mode=0,\n                     const unsigned int interpolation=1, const unsigned int boundary_conditions=0) const {\n      if (is_empty() || !p_warp) return *this;\n      if (mode && !is_sameXYZ(p_warp))\n        throw CImgArgumentException(_cimg_instance\n                                    \"warp(): Instance and specified relative warping field (%u,%u,%u,%u,%p) \"\n                                    \"have different XYZ dimensions.\",\n                                    cimg_instance,\n                                    p_warp._width,p_warp._height,p_warp._depth,p_warp._spectrum,p_warp._data);\n\n      CImg<T> res(p_warp._width,p_warp._height,p_warp._depth,_spectrum);\n\n      if (p_warp._spectrum==1) { // 1D warping\n        if (mode>=3) { // Forward-relative warp\n          res.fill((T)0);\n          if (interpolation>=1) // Linear interpolation\n            cimg_pragma_openmp(parallel for cimg_openmp_collapse(3) cimg_openmp_if_size(res.size(),4096))\n            cimg_forYZC(res,y,z,c) {\n              const t *ptrs0 = p_warp.data(0,y,z); const T *ptrs = data(0,y,z,c);\n              cimg_forX(res,x) res.set_linear_atX(*(ptrs++),x + (float)*(ptrs0++),y,z,c);\n            }\n          else // Nearest-neighbor interpolation\n            cimg_forYZC(res,y,z,c) {","sourceCodeStart":40045,"sourceCodeEnd":40081,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L40045-L40081","documentation":"In relative warping mode (mode != 0), CImg's warp()/get_warp() requires the warping field to have the same width, height, and depth as the image instance being warped (spectra may differ). When is_sameXYZ(p_warp) fails, it throws CImgArgumentException including the warp field's dimensions and data pointer so the mismatch is visible. Relative mode indexes the warp field with the same coordinates as the image, so mismatched XYZ sizes are meaningless.","triggerScenarios":"Calling img.warp(p_warp, 1 /* relative */) (or get_warp with mode!=0) where p_warp was built at a different resolution than img — e.g. warp field computed from a resized/downscaled image, or created with different width/height/depth. In absolute mode (mode==0) this check is skipped, so switching mode exposes the mismatch.","commonSituations":"Generating the displacement field at coarse resolution for performance then warping the full-size image; loading a precomputed warp of different dimensions; changing mode from 0 to 1 after upgrading code without resizing the field.","solutions":["Resize the warping field to match the image XYZ dimensions before warping: p_warp.resize(img.width(), img.height(), img.depth(), p_warp.spectrum(), 3).","Or call warp with mode=0 (absolute) if the field is meant to hold absolute coordinates, which does not require same XYZ sizes.","Ensure the warp field is derived from the same (or identically sized) source image as the one being warped.","Log/compare img.width()/height()/depth() against p_warp dimensions (they appear in the message) to find which pipeline stage changed size."],"exampleFix":"// before\nimg.warp(field, 1); // field is 320x240, img is 640x480 -> throws\n// after\nfield.resize(img.width(), img.height(), img.depth(), field.spectrum(), 3);\nimg.warp(field, 1); // XYZ dims now match","handlingStrategy":"validation","validationCode":"// C++\nif (mode != 0 && !(img.is_sameX(field) && img.is_sameY(field) && img.is_sameZ(field))) {\n    field.resize(img.width(), img.height(), img.depth(), field.spectrum(), 3); // linear resize\n}\nimg.warp(field, mode);","typeGuard":null,"tryCatchPattern":"try {\n    img.warp(field, mode, interp, bc);\n} catch (const cimg_library::CImgArgumentException& e) {\n    // parse/report dims from e.what(), or auto-align:\n    field.resize(img.width(), img.height(), img.depth(), field.spectrum(), 3);\n    img.warp(field, mode, interp, bc);\n}","preventionTips":["Use CImg's built-in is_sameXYZ(field) check before any relative-mode warp","Generate the warp field from the same, identically-sized image you intend to warp","Remember absolute mode (mode=0) has no dimension requirement — pick mode deliberately, not accidentally","Assert dimensions at pipeline stage boundaries so a resize step can't silently change one input"],"tags":["cimg","shape-mismatch","warp","dimension-mismatch"],"backgroundTag":"tensor-shape-mismatch","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"}