{"record":{"id":"1460eec484253766","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-1460ee","errorCode":null,"errorMessage":"[\" cimg_appname \"_math_parser] CImg<%s>: Function '%s()': Element to insert has invalid size %u (should be %u).","messagePattern":"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function '(.+?)\\(\\)': Element to insert has invalid size %u \\(should be %u\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":26343,"sourceCode":"      }\n\n      static double mp_da_insert_or_push(_cimg_math_parser& mp) {\n        const bool is_push_heap = mp.opcode[3]==~0U - 1, is_push = mp.opcode[3]>=~0U - 1;\n        const char *const s_op = is_push_heap?\"da_push_heap\":is_push?\"da_push\":\"da_insert\";\n        mp_check_list(mp,s_op);\n        const unsigned int\n          dim = (unsigned int)mp.opcode[4],\n          _dim = std::max(1U,dim),\n          nb_elts = (unsigned int)mp.opcode[5] - 6,\n          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));","sourceCodeStart":26325,"sourceCodeEnd":26361,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L26325-L26361","documentation":"Dynamic-array insert functions (da_push/da_insert family) require the inserted element to have the same vector dimension as the array's spectrum (_dim == img._spectrum). When the pushed element's size differs from the array's channel count, this error reports both the actual and expected sizes.","triggerScenarios":"Pushing a 2-element vector into a dynamic array created with dimension 3, e.g. mismatched dim argument vs the array image's spectrum.","commonSituations":"Changing the tuple size mid-algorithm; copy-pasted push calls with stale dim values; arrays created with da_init(h,dim1) but pushed with dim2-element values.","solutions":["Match the element size to the array's spectrum: resize the element or recreate the array with the correct dim.","Verify the dim argument passed to the push/insert opcode equals the array's channel count.","Re-create the array with da_init(h,correctDim) if the element size legitimately changed.","Audit all push sites in your expression to use a single consistent dim."],"exampleFix":"// before\narr.fill(\"da_init(10,3)\"); arr.fill(\"da_push([1,2])\"); // dim 2 != 3\n// after\narr.fill(\"da_init(10,3)\"); arr.fill(\"da_push([1,2,3])\");","handlingStrategy":"validation","validationCode":"if (elemDim != arr.spectrum())\n  throw std::invalid_argument(\"element size must match array spectrum\");","typeGuard":"bool dimsMatch(unsigned elemDim, const CImg<T>& arr) { return elemDim == arr.spectrum(); }","tryCatchPattern":"try { img.fill(pushExpr); } catch (const cimg_library::CImgArgumentException& e) { /* align dim with spectrum */ }","preventionTips":["Use one constant dim for all push sites","Create arrays with da_init(h,dim) matching payloads","Unit-test expressions with fixed element widths"],"tags":["cimg","math-parser","dynamic-array","size-mismatch"],"backgroundTag":"tensor-shape-mismatch","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"}