{"record":{"id":"a034b653abadaf60","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-a034b6","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":26347,"sourceCode":"        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));\n\n        if (!dim) // Scalar or vector1() elements\n          for (unsigned int k = 0; k<nb_elts; ++k) {\n            int index = pos + k;","sourceCodeStart":26329,"sourceCodeEnd":26365,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L26329-L26365","documentation":"This is the same invalid-element-size check as error 158 (thrown by the da_insert/da_push family at a slightly different site in the same function). It fires when the element's vector size _dim differs from the dynamic-array image's spectrum, reporting both values.","triggerScenarios":"Calling an insert-at-position MP opcode with an element whose dimension does not equal the array image's spectrum, e.g. inserting [1,2] into an array with spectrum 4.","commonSituations":"Insert operations in expression loops where element construction size varies; mismatched da_init dimension vs insert payloads; refactored expressions that changed tuple width.","solutions":["Make the inserted element's size equal the array spectrum before inserting.","Update the da_init call to create arrays with the dimension you actually insert.","Centralize element construction in the expression so its width is consistent.","Validate _dim against img.spectrum() in host code before evaluating the expression."],"exampleFix":"// before\narr.fill(\"da_insert(4,[9,9])\"); // array spectrum 3\n// after\narr.fill(\"da_insert(4,[9,9,9])\");","handlingStrategy":"validation","validationCode":"if (element.size() != arr.spectrum())\n  throw std::invalid_argument(\"inserted element size mismatch\");","typeGuard":"bool insertOk(const CImg<T>& elem, const CImg<T>& arr) { return elem.spectrum() == arr.spectrum(); }","tryCatchPattern":"try { img.fill(insertExpr); } catch (const cimg_library::CImgArgumentException& e) { /* pad/trim element to spectrum */ }","preventionTips":["Pad element vectors to the array dimension before insert","Keep tuple width consistent across expression refactors","Assert elem size equals arr.spectrum() in host code"],"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"}