Yalantis/uCrop · error · CImgArgumentException
"[" cimg_appname "_math_parser] CImg<
Error message
"[" cimg_appname "_math_parser] CImg<%s>: Function 'store()': Specified image dimensions (%d,%d,%d,%d) are invalid."
What it means
The math parser 'store()' function serializes an image into a memory buffer using caller-provided dimensions w,h,d,s. If any dimension is negative the geometry is meaningless, so a CImgArgumentException is thrown with the four requested dimensions before any serialization happens.
Solutions
- Clamp each dimension with max(0, expr) or validate w,h,d,s >= 0 before calling store().
- Fix the arithmetic producing negative dimensions (check start/end ordering in differences).
- Pass the actual image's dimensions (w,h,d,s) directly instead of computed values.
- Catch CImgArgumentException and report the requested geometry to the caller.
Example fix
// before: store(buf, w2-w1, h2-h1, d, s) // after: store(buf, max(0,w2-w1), max(0,h2-h1), d, s)
Defensive patterns
Strategy: validation
Validate before calling
if (w < 0 || h < 0 || d < 0 || s < 0)
throw std::runtime_error("store() dimensions must be non-negative"); Try / catch
try { img.evaluate(storeExpr); } catch (const CImgArgumentException& e) { log("store() geometry invalid: " << e.what()); } Prevention
- Clamp computed dimensions with max(0, expr)
- Avoid -1 'auto' sentinels — store() requires literal non-negative dims
- Unit-test dimension arithmetic with edge inputs
When it happens
Trigger: store(...,w,h,d,s,is_compressed) where one of _mp_arg(7..9) evaluates to a negative value — e.g. computing dimensions as a difference like w2-w1 that underflows, or a variable that was initialized to a negative sentinel.
Common situations: Dimension arithmetic bugs (end-before-start subtraction); formula parameterization errors where a user passes -1 as 'auto' sentinel but store() doesn't support sentinels; mismatches when storing cropped sub-images.
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/174c5da81ae4a814.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:29843
}
#ifdef cimg_mp_func_store
static double mp_store(_cimg_math_parser& mp) {
const double
*ptr1 = &_mp_arg(2),
*ptr2 = &_mp_arg(4) + 1;
const unsigned int
siz1 = (unsigned int)mp.opcode[3],
siz2 = (unsigned int)mp.opcode[5];
const int
w = (int)_mp_arg(6),
h = (int)_mp_arg(7),
d = (int)_mp_arg(8),
s = (int)_mp_arg(9);
const bool is_compressed = (bool)_mp_arg(10);
if (w<0 || h<0 || d<0 || s<0)
throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'store()': "
"Specified image dimensions (%d,%d,%d,%d) are invalid.",
pixel_type(),w,h,d,s);
CImg<charT> ss(siz2 + 1);
cimg_for_inX(ss,0,ss.width() - 2,i) ss[i] = (char)ptr2[i];
ss.back() = 0;
if (siz1) cimg_mp_func_store(ptr1 + 1,siz1,
(unsigned int)w,(unsigned int)h,(unsigned int)d,(unsigned int)s,
is_compressed,ss._data);
else cimg_mp_func_store(ptr1,1,(unsigned int)w,(unsigned int)h,(unsigned int)d,(unsigned int)s,
is_compressed,ss._data);
return cimg::type<double>::nan();
}
#endif
static double mp_s2v(_cimg_math_parser& mp) {
const double *ptrs = &_mp_arg(2);
const ulongT siz = (ulongT)mp.opcode[3];
longT ind = (longT)_mp_arg(4);View on GitHub (pinned to f788b534b4)