{"record":{"id":"99d314545d671fdb","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-99d314","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Function '%s()': Specified image #%u of size (%d,%d,%d,%d) cannot be used as dynamic array%s.\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function '(.+?)\\(\\)': 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":26353,"sourceCode":"          ind = (unsigned int)cimg::mod((int)_mp_arg(2),mp.imglist.width());\n        CImg<T> &img = mp.imglist[ind];\n        const int\n          siz = img?(int)cimg::float2uint((float)img[img._height - 1]):0,\n          pos0 = is_push?siz:(int)_mp_arg(3),\n          pos = pos0<0?pos0 + siz:pos0;\n\n        if (img && _dim!=img._spectrum)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function '%s()': \"\n                                      \"Element to insert has invalid size %u (should be %u).\",\n                                      mp.imgout.pixel_type(),s_op,_dim,img._spectrum);\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 '%s()': \"\n                                      \"Specified image #%u of size (%d,%d,%d,%d) cannot be used as dynamic array%s.\",\n                                      mp.imgout.pixel_type(),s_op,ind,\n                                      img.width(),img.height(),img.depth(),img.spectrum(),\n                                      img._width==1 && img._depth==1?\"\":\" (contains invalid element counter)\");\n        if (pos<0 || pos>siz)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function '%s()': \"\n                                      \"Invalid position %d (not in range -%d...%d).\",\n                                      mp.imgout.pixel_type(),s_op,pos0,siz,siz);\n\n        if (siz + nb_elts + 1>=img._height) // Increase size of dynamic array, if necessary\n          img.resize(1,2*siz + nb_elts + 1,1,_dim,0);\n\n        if (pos!=siz) // Move existing data in dynamic array\n          cimg_forC(img,c) std::memmove(img.data(0,pos + nb_elts,0,c),img.data(0,pos,0,c),(siz - pos)*sizeof(T));\n\n        if (!dim) // Scalar or vector1() elements\n          for (unsigned int k = 0; k<nb_elts; ++k) {\n            int index = pos + k;\n            img[index] = (T)_mp_arg(6 + k);\n            if (is_push_heap) while (index>0) { // Heapify-up\n                const int index_parent = (index - 1)/2;\n                if (img[index]<img[index_parent]) {\n                  cimg::swap(img[index],img[index_parent]);\n                  index = index_parent; }","sourceCodeStart":26335,"sourceCodeEnd":26371,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L26335-L26371","documentation":"CImg's math parser function (a dynamic-array operation like da_insert) requires the referenced image list entry to be a valid dynamic array: a single-column, single-depth image whose last row stores the element count. This error is thrown when the image #ind has wrong dimensions or a corrupt element counter, so it cannot be interpreted as a dynamic array. The suffix ' (contains invalid element counter)' is appended when width/depth are OK but the stored counter is out of range.","triggerScenarios":"Calling a dynamic-array math function (e.g. da_insert) with an image index pointing to an image that is not 1xNx1xC, or whose last stored value is negative or larger than height-1 (e.g. the image was created/modified without using da_* functions).","commonSituations":"Using plain fill/copy/resize operations on an image that da_* functions previously managed, destroying the element-counter row; passing the wrong image index into the math expression; reusing images from incompatible code paths in G'MIC-style scripts.","solutions":["Verify the image index used in the expression points to an image actually created by dynamic-array functions (da_insert/da_remove/...).","Ensure the image has dimensions (1,N,1,C): recreate it via da_* functions if it was resized or overwritten elsewhere.","Check the last row of the image holds a valid element counter in 0..height-1; reset the array by re-initializing with da_size/da_insert.","Print the image dimensions in the expression (e.g. size(#ind)) to confirm shape before the failing call."],"exampleFix":"// before: using a plain image as dynamic array\nfoo: fill 0 resize 16,1,1,1 da_insert(#0,0,42)\n// after: initialize via dynamic-array API\nfoo: da_insert(#0,0,42)","handlingStrategy":"validation","validationCode":"// Check the image is a valid dynamic array before da_* calls\nfunction isValidDa(img) { return img && img.width === 1 && img.depth === 1 && img.counter >= 0 && img.counter <= img.height - 1; }\nif (!isValidDa(images[ind])) throw new Error('image ' + ind + ' is not a dynamic array');","typeGuard":"function isDynamicArray(img) { return Boolean(img) && img.width === 1 && img.depth === 1 && Number.isInteger(img.height) && img.lastRowCounter >= 0 && img.lastRowCounter <= img.height - 1; }","tryCatchPattern":"try { result = evalMath(expr); } catch (e) { if (String(e).includes('cannot be used as dynamic array')) { rebuildArray(ind); } else throw e; }","preventionTips":["Only manipulate da_* arrays with da_* functions","Never resize or overwrite dynamic-array images with generic image ops","Log image dimensions before array operations","Keep a fixed index convention for array images in multi-image expressions"],"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"}