Yalantis/uCrop · error · CImgArgumentException
sort(): Invalid specified axis '%c' (should be { x | y | z |
Error message
sort(): Invalid specified axis '%c' (should be { x | y | z | c }). What it means
CImg<T>::sort(axis) sorts pixel values along one of the four image axes identified by the characters 'x','y','z','c'. Any other axis character is rejected by CImgArgumentException at the switch default.
Source
Thrown at ucrop/src/main/jni/CImg.h:33347
perm.assign(_height);
get_crop(0,0,0,0,0,_height - 1,0,0).sort(perm,is_increasing);
CImg<T> img(*this,false);
cimg_forXYZC(*this,x,y,z,c) (*this)(x,y,z,c) = img(x,perm[y],z,c);
} break;
case 'z' : {
perm.assign(_depth);
get_crop(0,0,0,0,0,0,_depth - 1,0).sort(perm,is_increasing);
CImg<T> img(*this,false);
cimg_forXYZC(*this,x,y,z,c) (*this)(x,y,z,c) = img(x,y,perm[z],c);
} break;
case 'c' : {
perm.assign(_spectrum);
get_crop(0,0,0,0,0,0,0,_spectrum - 1).sort(perm,is_increasing);
CImg<T> img(*this,false);
cimg_forXYZC(*this,x,y,z,c) (*this)(x,y,z,c) = img(x,y,z,perm[c]);
} break;
default :
throw CImgArgumentException(_cimg_instance
"sort(): Invalid specified axis '%c' "
"(should be { x | y | z | c }).",
cimg_instance,axis);
}
return *this;
}
//! Sort pixel values \newinstance.
CImg<T> get_sort(const bool is_increasing=true, const char axis=0) const {
return (+*this).sort(is_increasing,axis);
}
template<typename t>
CImg<T>& _quicksort(const long indm, const long indM, CImg<t>& permutations,
const bool is_increasing, const bool is_permutations) {
if (indm<indM) {
const long mid = (indm + indM)/2;
if (is_increasing) {View on GitHub (pinned to f788b534b4)
Solutions
- Pass exactly one of 'x','y','z','c' (lowercase)
- Validate/normalize the axis character before the call and reject invalid input early
- Map indices 0-3 to 'x','y','z','c' if your config stores numeric axes
Example fix
// before
img.sort(userAxis); // userAxis == 'X'
// after
char ax = std::tolower(userAxis);
if (ax!='x' && ax!='y' && ax!='z' && ax!='c') throw std::invalid_argument("axis");
img.sort(ax, true); Defensive patterns
Strategy: validation
Validate before calling
if (axis!='x' && axis!='y' && axis!='z' && axis!='c') throw std::invalid_argument("sort axis must be x, y, z or c"); Type guard
bool isValidAxis(char a) { return a=='x' || a=='y' || a=='z' || a=='c'; } Try / catch
try { img.sort(axis, true); } catch (CImgArgumentException& e) { /* normalize axis or report invalid axis */ } Prevention
- Always pass lowercase axis chars
- Whitelist axis chars when they come from config or CLI
- Map numeric axes 0-3 to 'x','y','z','c' explicitly
When it happens
Trigger: Calling sort(axis, is_increasing) with axis not in {'x','y','z','c'} — e.g. 'X', 'w', 0, or a variable holding an unexpected char.
Common situations: Typo or case mismatch ('X' vs 'x'); passing an axis taken from user config or CLI without validation; confusion between axis chars and axis indices in other APIs.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- mirror(): Invalid specified axis '%c'.
- "[" cimg_appname "_math_parser] CImg<%s>: Function 'polygon(
- "[" cimg_appname "_math_parser] CImg<%s>: Function 'polygon(
- invert(): Specified lambda (%g) should be >=0.
- %s
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/2f26ccd2926400fb.
Report an issue: GitHub.