{"record":{"id":"29bd1eb27343223f","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-29bd1e","errorCode":null,"errorMessage":"\"[\" 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.\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'da_remove\\(\\)': 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":26401,"sourceCode":"                if (img[index]<img[index_parent]) {\n                  T *ptr0 = img.data(0,index), *ptr1 = img.data(0,index_parent);\n                  cimg_forC(img,c) { cimg::swap(*ptr0,*ptr1); ptr0+=img._height; ptr1+=img._height; }\n                  index = index_parent;\n                }\n                else break;\n              }\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);","sourceCodeStart":26383,"sourceCodeEnd":26419,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L26383-L26419","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n da_remove(#2,0)\n// after: verify index and array validity first\n if (da_size(#2)>0, da_remove(#2,0), error(\"image #2 is not a valid dynamic array\"))","handlingStrategy":"validation","validationCode":"// Verify array validity and non-zero size before da_remove\nconst siz = isValidDynamicArray(images[ind]) ? images[ind].counter : -1;\nif (siz <= 0) throw new Error('da_remove: array empty or invalid');","typeGuard":"function isRemovableDa(img) { return Boolean(img) && img.width === 1 && img.depth === 1 && img.counter > 0 && img.counter <= img.height - 1; }","tryCatchPattern":"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; }","preventionTips":["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"],"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"}