Yalantis/uCrop · error · CImgArgumentException
"[" cimg_appname "_math_parser] CImg<
Error message
"[" cimg_appname "_math_parser] CImg<%s>: Function 'da_remove()': Dynamic array is empty."
What it means
mp_da_remove() throws this when the dynamic array is valid but has zero elements (stored element count siz==0), so there is nothing to remove. Removing from an empty dynamic array is treated as an invalid operation rather than a no-op.
Solutions
- Check da_size(#ind)>0 before calling da_remove.
- Restructure loops to stop when the array is empty.
- Re-populate the array with da_insert if it should contain elements at this point.
Example fix
// before da_remove(#0,0) // after if (da_size(#0)>0, da_remove(#0,0), 0)
Defensive patterns
Strategy: validation
Validate before calling
// Only remove when the array has elements
if (da_size(ind) > 0) { remove(ind, start, end); } Type guard
function isNonEmptyDa(img) { return Boolean(img) && img.counter > 0; } Try / catch
try { evalMath(expr); } catch (e) { if (String(e).includes('Dynamic array is empty')) { skipOrRepopulate(); } else throw e; } Prevention
- Check da_size before every da_remove
- Terminate drain loops on da_size==0
- Avoid re-running drain scripts on already-emptied arrays
When it happens
Trigger: Calling da_remove() on an image whose element counter is 0 — typically after all elements were already removed by previous da_remove calls, or the array was initialized but never filled.
Common situations: Loops that pop elements without checking emptiness; scripts that drain a queue/stack stored in a dynamic array; re-running a script on already-processed images.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 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/1666c0e83418b55f.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:26407
}
}
img[img._height - 1] = (T)cimg::uint2float(siz + nb_elts);
return cimg::type<double>::nan();
}
static double mp_da_remove(_cimg_math_parser& mp) {
mp_check_list(mp,"da_remove");
const unsigned int ind = (unsigned int)cimg::mod((int)_mp_arg(2),mp.imglist.width());
CImg<T> &img = mp.imglist[ind];
int siz = img?(int)cimg::float2uint((float)img[img._height - 1]):0;
if (img && (img._width!=1 || img._depth!=1 || siz<0 || siz>img.height() - 1))
throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'da_remove()': "
"Specified image #%u of size (%d,%d,%d,%d) cannot be used as dynamic array%s.",
mp.imgout.pixel_type(),ind,
img.width(),img.height(),img.depth(),img.spectrum(),
img._width==1 && img._depth==1?"":" (contains invalid element counter)");
if (!siz)
throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'da_remove()': "
"Dynamic array is empty.",
mp.imgout.pixel_type());
int
start0 = mp.opcode[3]==~0U?siz - 1:_mp_arg(3),
end0 = mp.opcode[4]==~0U?start0:_mp_arg(4),
start = start0<0?start0 + siz:start0,
end = end0<0?end0 + siz:end0;
if (start<0 || start>=siz || end<0 || end>=siz || start>end)
throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'da_remove()': "
"Invalid starting (%d) and ending (%d) positions "
"(not ordered, in range -%d...%d).",
mp.imgout.pixel_type(),start0,end0,siz,siz - 1);
if (end<siz - 1) // Move remaining data in dynamic array
cimg_forC(img,c) std::memmove(img.data(0,start,0,c),img.data(0,end + 1,0,c),(siz - 1 - end)*sizeof(T));
siz-=end - start + 1;
if (img.height()>32 && siz<img.height()/8) // Reduce size of dynamic array
img.resize(1,std::max(2*siz + 1,32),1,-100,0);
img[img._height - 1] = (T)cimg::uint2float(siz);View on GitHub (pinned to f788b534b4)