Yalantis/uCrop · error · CImgArgumentException
"[" cimg_appname "_math_parser] CImg<
Error message
"[" cimg_appname "_math_parser] CImg<%s>: Function 'sort()': Arguments 'nb_elts=%g' and 'siz_elt=%g' are invalid for sorting a vector of size %u."
What it means
The math parser 'sort()' function sorts a vector in blocks: nb_elts blocks of siz_elt values each. The product siz_elt*nb_elts must not exceed the vector size 'siz', and siz_elt must be >= 1; otherwise a CImgArgumentException reports the conflicting nb_elts/siz_elt values against the actual vector size.
Solutions
- Ensure siz_elt >= 1 and ceil-based nb_elts so that nb_elts*siz_elt <= siz: pass nb_elts = siz/siz_elt (integer division).
- Recompute block parameters from the actual vector size instead of hard-coding them.
- If the goal is a full sort, use the simpler one-argument sort form rather than block parameters.
- Catch CImgArgumentException and log the vector size to select correct block parameters.
Example fix
// before: sort(V, 10, 4) // 40 > 32 elements // after: sort(V, 8, 4) // 8*4 = 32
Defensive patterns
Strategy: validation
Validate before calling
if (siz_elt < 1 || siz_elt * nb_elts > siz)
throw std::runtime_error("sort block parameters do not fit vector size"); Try / catch
try { img.evaluate(sortExpr); } catch (const CImgArgumentException& e) { log("sort() params invalid: " << e.what()); } Prevention
- Derive nb_elts = siz / siz_elt instead of hard-coding
- Assert siz_elt >= 1 before building the expression
- Re-derive block parameters whenever vector size changes
When it happens
Trigger: sort(ptr,siz,...,nb_elts,siz_elt,sort_index) where nb_elts*siz_elt > siz (e.g. sorting 10 blocks of 4 on a vector of 32) or siz_elt == 0, typically because block parameters were hard-coded and the vector dimension changed.
Common situations: Changing vector length (e.g. after resizing a feature vector) without updating sort block parameters; passing 0 or negative-derived siz_elt; computing nb_elts from a formula that over-estimates.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- "[" cimg_appname "_math_parser] CImg<
- "[" cimg_appname "_math_parser] CImg<
- [" cimg_appname "_math_parser] CImg<
- "[" cimg_appname "_math_parser] CImg<
- [" cimg_appname "_math_parser] CImg<
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/1b066711208377e5.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:29782
m = (unsigned int)mp.opcode[6];
const bool use_LU = (bool)_mp_arg(7);
CImg<doubleT>(ptrd,m,k,1,1,true) = CImg<doubleT>(ptr2,m,l,1,1,false).
solve(CImg<doubleT>(ptr1,k,l,1,1,true),use_LU);
return cimg::type<double>::nan();
}
static double mp_sort(_cimg_math_parser& mp) {
double *const ptrd = &_mp_arg(1) + 1;
const double *const ptrs = &_mp_arg(2) + 1;
const bool is_increasing = (bool)_mp_arg(4);
const unsigned int
siz = (unsigned int)mp.opcode[3],
nb_elts = mp.opcode[5]==~0U?siz:(unsigned int)_mp_arg(5),
siz_elt = (unsigned int)_mp_arg(6),
sort_index = std::min((unsigned int)_mp_arg(7),siz_elt - 1);
const ulongT sn = siz_elt*nb_elts;
if (sn>siz || siz_elt<1)
throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'sort()': "
"Arguments 'nb_elts=%g' and 'siz_elt=%g' are invalid "
"for sorting a vector of size %u.",
mp.imgin.pixel_type(),_mp_arg(5),_mp_arg(6),siz);
CImg<doubleT>(ptrd,siz_elt,nb_elts,1,1,true) = CImg<doubleT>(ptrs,siz_elt,nb_elts,1,1,true).
shift(-(int)sort_index,0,0,0,2).get_sort(is_increasing,siz_elt>1?'y':0).shift((int)sort_index,0,0,0,2);
if (sn<siz) CImg<doubleT>(ptrd + sn,siz - sn,1,1,1,true) = CImg<doubleT>(ptrs + sn,siz - sn,1,1,1,true);
return cimg::type<double>::nan();
}
static double mp_sqr(_cimg_math_parser& mp) {
return cimg::sqr(_mp_arg(2));
}
static double mp_sqrt(_cimg_math_parser& mp) {
return std::sqrt(_mp_arg(2));
}
static double mp_srand(_cimg_math_parser& mp) {View on GitHub (pinned to f788b534b4)