{"record":{"id":"1666c0e83418b55f","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-1666c0","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'da_remove()': Dynamic array is empty.\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'da_remove\\(\\)': Dynamic array is empty\\.\"","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":26407,"sourceCode":"              }\n          }\n        img[img._height - 1] = (T)cimg::uint2float(siz + nb_elts);\n        return cimg::type<double>::nan();\n      }\n\n      static double mp_da_remove(_cimg_math_parser& mp) {\n        mp_check_list(mp,\"da_remove\");\n        const unsigned int ind = (unsigned int)cimg::mod((int)_mp_arg(2),mp.imglist.width());\n        CImg<T> &img = mp.imglist[ind];\n        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_remove()': \"\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        if (!siz)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'da_remove()': \"\n                                      \"Dynamic array is empty.\",\n                                      mp.imgout.pixel_type());\n        int\n          start0 = mp.opcode[3]==~0U?siz - 1:_mp_arg(3),\n          end0 = mp.opcode[4]==~0U?start0:_mp_arg(4),\n          start = start0<0?start0 + siz:start0,\n          end = end0<0?end0 + siz:end0;\n        if (start<0 || start>=siz || end<0 || end>=siz || start>end)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'da_remove()': \"\n                                      \"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);","sourceCodeStart":26389,"sourceCodeEnd":26425,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L26389-L26425","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n da_remove(#0,0)\n// after\n if (da_size(#0)>0, da_remove(#0,0), 0)","handlingStrategy":"validation","validationCode":"// Only remove when the array has elements\nif (da_size(ind) > 0) { remove(ind, start, end); }","typeGuard":"function isNonEmptyDa(img) { return Boolean(img) && img.counter > 0; }","tryCatchPattern":"try { evalMath(expr); } catch (e) { if (String(e).includes('Dynamic array is empty')) { skipOrRepopulate(); } else throw e; }","preventionTips":["Check da_size before every da_remove","Terminate drain loops on da_size==0","Avoid re-running drain scripts on already-emptied arrays"],"tags":["cimg","math-parser","dynamic-array","empty-collection"],"backgroundTag":"empty-required-field","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}