{"record":{"id":"1b57ced52469ed8f","repo":"Yalantis/uCrop","slug":"get-split-instance-cannot-be-split-along-c-axi","errorCode":null,"errorMessage":"get_split(): Instance cannot be split along %c-axis into %u blocks.","messagePattern":"get_split\\(\\): Instance cannot be split along %c-axis into %u blocks\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":41809,"sourceCode":"              else get_slices(p*dp,_depth - 1).move_to(res[p]);\n          }\n        } break;\n        case 'c' : {\n          if (max_parts==1 || dp>=_spectrum) res.assign(*this);\n          else {\n            res.assign(std::min(max_parts,_spectrum/dp + (_spectrum%dp?1:0)));\n            cimg_pragma_openmp(parallel for cimg_openmp_if(res._width>=(cimg_openmp_sizefactor)*128 &&\n                                                           _width*_height*_depth>=128))\n            cimglist_for(res,p)\n              if (p!=res.width() - 1) get_channels(p*dp,(p + 1)*dp - 1).move_to(res[p]);\n              else get_channels(p*dp,_spectrum - 1).move_to(res[p]);\n          }\n        }\n        }\n      } else if (nb>0) { // Split by number of (non-homogeneous) blocks\n        const unsigned int siz = _axis=='x'?_width:_axis=='y'?_height:_axis=='z'?_depth:_axis=='c'?_spectrum:0;\n        if ((unsigned int)nb>siz)\n          throw CImgArgumentException(_cimg_instance\n                                      \"get_split(): Instance cannot be split along %c-axis into %u blocks.\",\n                                      cimg_instance,\n                                      axis,nb);\n        if (nb==1) res.assign(*this);\n        else {\n          int err = (int)siz;\n          unsigned int _p = 0;\n          switch (_axis) {\n          case 'x' :\n            cimg_forX(*this,p) if ((err-=nb)<=0) {\n              get_columns(_p,p).move_to(res);\n              if (res._width>=mp1) { get_columns(p,_width - 1).move_to(res); break; }\n              err+=(int)siz; _p = p + 1U;\n            }\n            break;\n          case 'y' :\n            cimg_forY(*this,p) if ((err-=nb)<=0) {\n              get_rows(_p,p).move_to(res);","sourceCodeStart":41791,"sourceCodeEnd":41827,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L41791-L41827","documentation":"CImg's get_split() was asked to split an image into more blocks along the given axis than there are pixels/elements along that axis. The library computes the axis size from 'x','y','z' or 'c' (width, height, depth or spectrum) and throws when the requested block count 'nb' exceeds it.","triggerScenarios":"Calling img.get_split(axis, nb) with nb larger than the instance size along 'axis' (e.g. get_split('x', 100) on a 64-wide image), or passing an axis character where the resolved size is small (e.g. 'z' on a 2D image where _depth==1).","commonSituations":"Hardcoded block counts used with images of varying dimensions; splitting along 'z' or 'c' on grayscale 2D images where those axes have size 1; off-by-one or percent-vs-count confusion when computing nb.","solutions":["Reduce the nb argument to be <= the image size along the given axis","Verify the axis character is the intended one ('x' vs 'z' vs 'c')","Compute nb dynamically from the image dimensions (e.g. width/blockSize) before calling get_split"],"exampleFix":"// before\nCImgList<T> blocks = img.get_split('x', 100);\n// after\nunsigned int nb = std::min(100u, img.width());\nCImgList<T> blocks = img.get_split('x', nb);","handlingStrategy":"validation","validationCode":"if (nb > (unsigned)(axis=='x'?img.width():axis=='y'?img.height():axis=='z'?img.depth():img.spectrum())) {\n  nb = /* clamp */ 1; // or adjust axis\n}","typeGuard":"bool canSplit(const cimg_library::CImg<unsigned char>& img, char axis, unsigned nb) {\n  unsigned siz = axis=='x'?img.width():axis=='y'?img.height():axis=='z'?img.depth():axis=='c'?img.spectrum():0;\n  return siz > 0 && nb <= siz;\n}","tryCatchPattern":"try {\n  blocks = img.get_split(axis, nb);\n} catch (cimg_library::CImgArgumentException& e) {\n  blocks = img.get_split(axis, 1); // fall back to a single block\n}","preventionTips":["Always derive block counts from the image dimensions, never hardcode","Remember depth/spectrum are 1 for typical 2D grayscale images","Assert is_sameXYZ-style size checks in debug builds"],"tags":["cimg","image-processing","argument-validation","split"],"backgroundTag":"value-out-of-range","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}