Yalantis/uCrop · error · CImgArgumentException
"[" cimg_appname "_math_parser] CImg<%s>: Function 'da_remov
Error message
"[" 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."
What it means
mp_da_remove() removes elements from a dynamic array stored as a single-column image. Before removing, it validates that image #ind is 1xNx1xC with a valid element counter in its last row. This error is thrown when the target image cannot be interpreted as a dynamic array (wrong dimensions or corrupt counter).
Source
Thrown at ucrop/src/main/jni/CImg.h:26401
if (img[index]<img[index_parent]) {
T *ptr0 = img.data(0,index), *ptr1 = img.data(0,index_parent);
cimg_forC(img,c) { cimg::swap(*ptr0,*ptr1); ptr0+=img._height; ptr1+=img._height; }
index = index_parent;
}
else break;
}
}
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);View on GitHub (pinned to f788b534b4)
Solutions
- Confirm the image index in da_remove refers to a dynamic array created and maintained by da_* functions.
- Rebuild the array (re-insert elements with da_insert) if its structure was altered by other operations.
- Check that the element counter (last row) is within 0..height-1; correct or reinitialize the array.
- Guard the expression with da_size(#ind) checks before calling da_remove.
Example fix
// before
da_remove(#2,0)
// after: verify index and array validity first
if (da_size(#2)>0, da_remove(#2,0), error("image #2 is not a valid dynamic array")) Defensive patterns
Strategy: validation
Validate before calling
// Verify array validity and non-zero size before da_remove
const siz = isValidDynamicArray(images[ind]) ? images[ind].counter : -1;
if (siz <= 0) throw new Error('da_remove: array empty or invalid'); Type guard
function isRemovableDa(img) { return Boolean(img) && img.width === 1 && img.depth === 1 && img.counter > 0 && img.counter <= img.height - 1; } Try / catch
try { evalMath('da_remove(#' + ind + ',' + start + ',' + end + ')'); } catch (e) { if (String(e).includes('da_remove')) { log('invalid array at index ' + ind); rebuild(ind); } else throw e; } Prevention
- Guard all da_remove calls with da_size checks
- Track array indices in a constant mapping instead of magic numbers
- Avoid interleaving regular image operations with dynamic-array images
When it happens
Trigger: Calling da_remove(#ind,...) where the image at index ind is not a 1-column/1-depth image, is empty (img==0 handled by siz=0 path), or its stored element count is negative or exceeds height-1.
Common situations: Operating on an image that was overwritten by regular drawing/fill operations; wrong image index in a multi-image expression; constructing the array manually with an incorrect counter value.
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<%s>: Function '%s()': S
- "[" cimg_appname "_math_parser] CImg<%s>: Function 'da_size(
- [" cimg_appname "_math_parser] CImg<%s>::%s: %s%s %s%s (of t
- [" cimg_appname "_math_parser] CImg<%s>::%s: %s%s Specified
- [" cimg_appname "_math_parser] CImg<%s>: Function '%s()': Sp
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/29bd1eb27343223f.
Report an issue: GitHub.