Yalantis/uCrop · error · CImgArgumentException
get_split(): Instance cannot be split along %c-axis into %u…
Error message
get_split(): Instance cannot be split along %c-axis into %u blocks.
What it means
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.
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
Example fix
// before
CImgList<T> blocks = img.get_split('x', 100);
// after
unsigned int nb = std::min(100u, img.width());
CImgList<T> blocks = img.get_split('x', nb); Defensive patterns
Strategy: validation
Validate before calling
if (nb > (unsigned)(axis=='x'?img.width():axis=='y'?img.height():axis=='z'?img.depth():img.spectrum())) {
nb = /* clamp */ 1; // or adjust axis
} Type guard
bool canSplit(const cimg_library::CImg<unsigned char>& img, char axis, unsigned nb) {
unsigned siz = axis=='x'?img.width():axis=='y'?img.height():axis=='z'?img.depth():axis=='c'?img.spectrum():0;
return siz > 0 && nb <= siz;
} Try / catch
try {
blocks = img.get_split(axis, nb);
} catch (cimg_library::CImgArgumentException& e) {
blocks = img.get_split(axis, 1); // fall back to a single block
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- "[" cimg_appname "_math_parser] CImg<
- "[" cimg_appname "_math_parser] CImg<
- "[" cimg_appname "_math_parser] CImg<
- CImg< >::streamline(): Invalid specified integration length…
- deriche(): Invalid specified axis '%c'.
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/1b57ced52469ed8f.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:41809
else get_slices(p*dp,_depth - 1).move_to(res[p]);
}
} break;
case 'c' : {
if (max_parts==1 || dp>=_spectrum) res.assign(*this);
else {
res.assign(std::min(max_parts,_spectrum/dp + (_spectrum%dp?1:0)));
cimg_pragma_openmp(parallel for cimg_openmp_if(res._width>=(cimg_openmp_sizefactor)*128 &&
_width*_height*_depth>=128))
cimglist_for(res,p)
if (p!=res.width() - 1) get_channels(p*dp,(p + 1)*dp - 1).move_to(res[p]);
else get_channels(p*dp,_spectrum - 1).move_to(res[p]);
}
}
}
} else if (nb>0) { // Split by number of (non-homogeneous) blocks
const unsigned int siz = _axis=='x'?_width:_axis=='y'?_height:_axis=='z'?_depth:_axis=='c'?_spectrum:0;
if ((unsigned int)nb>siz)
throw CImgArgumentException(_cimg_instance
"get_split(): Instance cannot be split along %c-axis into %u blocks.",
cimg_instance,
axis,nb);
if (nb==1) res.assign(*this);
else {
int err = (int)siz;
unsigned int _p = 0;
switch (_axis) {
case 'x' :
cimg_forX(*this,p) if ((err-=nb)<=0) {
get_columns(_p,p).move_to(res);
if (res._width>=mp1) { get_columns(p,_width - 1).move_to(res); break; }
err+=(int)siz; _p = p + 1U;
}
break;
case 'y' :
cimg_forY(*this,p) if ((err-=nb)<=0) {
get_rows(_p,p).move_to(res);View on GitHub (pinned to f788b534b4)