{"record":{"id":"a098da1cf7c3650c","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-a098da","errorCode":null,"errorMessage":"\"[\" 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.\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'da_size\\(\\)': Specified image #%u of size \\((.+?),(.+?),(.+?),(.+?)\\) cannot be used as dynamic array(.+?)\\.\"","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":26435,"sourceCode":"                                      \"Invalid starting (%d) and ending (%d) positions \"\n                                      \"(not ordered, in range -%d...%d).\",\n                                      mp.imgout.pixel_type(),start0,end0,siz,siz - 1);\n        if (end<siz - 1) // Move remaining data in dynamic array\n          cimg_forC(img,c) std::memmove(img.data(0,start,0,c),img.data(0,end + 1,0,c),(siz - 1 - end)*sizeof(T));\n        siz-=end - start + 1;\n        if (img.height()>32 && siz<img.height()/8) // Reduce size of dynamic array\n          img.resize(1,std::max(2*siz + 1,32),1,-100,0);\n        img[img._height - 1] = (T)cimg::uint2float(siz);\n        return cimg::type<double>::nan();\n      }\n\n      static double mp_da_size(_cimg_math_parser& mp) {\n        mp_check_list(mp,\"da_size\");\n        const unsigned int ind = (unsigned int)cimg::mod((int)_mp_arg(2),mp.imglist.width());\n        CImg<T> &img = mp.imglist[ind];\n        const int siz = img?(int)cimg::float2uint((float)img[img._height - 1]):0;\n        if (img && (img._width!=1 || img._depth!=1 || siz<0 || siz>img.height() - 1))\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'da_size()': \"\n                                      \"Specified image #%u of size (%d,%d,%d,%d) cannot be used as dynamic array%s.\",\n                                      mp.imgout.pixel_type(),ind,\n                                      img.width(),img.height(),img.depth(),img.spectrum(),\n                                      img._width==1 && img._depth==1?\"\":\" (contains invalid element counter)\");\n        return siz;\n      }\n\n      static double mp_date(_cimg_math_parser& mp) {\n        const unsigned int\n          siz_out = (unsigned int)mp.opcode[2],\n          siz_arg1 = (unsigned int)mp.opcode[4],\n          siz_arg2 = (unsigned int)mp.opcode[6];\n        double *ptr_out = &_mp_arg(1) + (siz_out?1:0);\n        const double\n          *ptr_arg1 = siz_arg1==~0U?0:&_mp_arg(3) + (siz_arg1?1:0),\n          *ptr_arg2 = siz_arg2==~0U?0:&_mp_arg(5) + 1;\n\n        if (!ptr_arg2) { // No filename specified","sourceCodeStart":26417,"sourceCodeEnd":26453,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L26417-L26453","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Point da_size at the correct image index that holds a da_*-managed array.","Recreate the dynamic array with da_insert if its structure was altered.","Check dimensions with size(#ind) and confirm they are (1,N,1,C) before querying."],"exampleFix":"// before\n n = da_size(#1)\n// after: ensure array exists/valid, default to 0\n n = (N1>0 && i[#1,N1-1]>=0)?da_size(#1):0","handlingStrategy":"validation","validationCode":"// Confirm dimensions before da_size\nfunction canQuerySize(img) { return img && img.width === 1 && img.depth === 1; }\nconst n = canQuerySize(images[ind]) ? daSize(ind) : 0;","typeGuard":"function isDaShape(img) { return Boolean(img) && img.width === 1 && img.depth === 1; }","tryCatchPattern":"try { n = evalMath('da_size(#' + ind + ')'); } catch (e) { if (String(e).includes('da_size')) { n = 0; } else throw e; }","preventionTips":["Keep dynamic arrays in dedicated, documented image indices","Assert shape (1,N,1,C) once at pipeline start","Never write raw values into array images"],"tags":["cimg","math-parser","dynamic-array","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}