Yalantis/uCrop · error · CImgArgumentException

"[" cimg_appname "_math_parser] CImg<%s>: Function 'da_size(

Error message

"[" cimg_appname "_math_parser] CImg<%s>: Function 'da_size()': Specified image #%u of size (%d,%d,%d,%d) cannot be used as dynamic array%s."

What it means

mp_da_size() returns the element count of a dynamic array stored in an image list entry. It first validates that image #ind is a valid dynamic array (1xNx1xC with a counter in 0..height-1). This error is thrown when the image cannot be interpreted as such.

Source

Thrown at ucrop/src/main/jni/CImg.h:26435

                                      "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);
        return cimg::type<double>::nan();
      }

      static double mp_da_size(_cimg_math_parser& mp) {
        mp_check_list(mp,"da_size");
        const unsigned int ind = (unsigned int)cimg::mod((int)_mp_arg(2),mp.imglist.width());
        CImg<T> &img = mp.imglist[ind];
        const 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_size()': "
                                      "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)");
        return siz;
      }

      static double mp_date(_cimg_math_parser& mp) {
        const unsigned int
          siz_out = (unsigned int)mp.opcode[2],
          siz_arg1 = (unsigned int)mp.opcode[4],
          siz_arg2 = (unsigned int)mp.opcode[6];
        double *ptr_out = &_mp_arg(1) + (siz_out?1:0);
        const double
          *ptr_arg1 = siz_arg1==~0U?0:&_mp_arg(3) + (siz_arg1?1:0),
          *ptr_arg2 = siz_arg2==~0U?0:&_mp_arg(5) + 1;

        if (!ptr_arg2) { // No filename specified

View on GitHub (pinned to f788b534b4)

Solutions

  1. Point da_size at the correct image index that holds a da_*-managed array.
  2. Recreate the dynamic array with da_insert if its structure was altered.
  3. Check dimensions with size(#ind) and confirm they are (1,N,1,C) before querying.

Example fix

// before
 n = da_size(#1)
// after: ensure array exists/valid, default to 0
 n = (N1>0 && i[#1,N1-1]>=0)?da_size(#1):0
Defensive patterns

Strategy: validation

Validate before calling

// Confirm dimensions before da_size
function canQuerySize(img) { return img && img.width === 1 && img.depth === 1; }
const n = canQuerySize(images[ind]) ? daSize(ind) : 0;

Type guard

function isDaShape(img) { return Boolean(img) && img.width === 1 && img.depth === 1; }

Try / catch

try { n = evalMath('da_size(#' + ind + ')'); } catch (e) { if (String(e).includes('da_size')) { n = 0; } else throw e; }

Prevention

When it happens

Trigger: Calling da_size(#ind) on an image with width!=1 or depth!=1, or whose stored element counter is negative or greater than height-1.

Common situations: Querying the size of a regular multi-column image by mistake; the array was corrupted by direct writes or resize; wrong image index in the expression.

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


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/a098da1cf7c3650c. Report an issue: GitHub.