{"record":{"id":"322067ae127920aa","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-322067","errorCode":null,"errorMessage":"[\" cimg_appname \"_math_parser] CImg<%s>: Function '%s()': Specified dynamic array #%u contains no elements.","messagePattern":"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function '(.+?)\\(\\)': Specified dynamic array #%u contains no elements\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":26269,"sourceCode":"\n      static double mp_da_back_or_pop(_cimg_math_parser& mp) {\n        const bool is_pop_heap = mp.opcode[4]==2, is_pop = (bool)mp.opcode[4];\n        const char *const s_op = is_pop_heap?\"da_pop_heap\":is_pop?\"da_pop\":\"da_back\";\n        mp_check_list(mp,s_op);\n        const unsigned int\n          dim = (unsigned int)mp.opcode[2],\n          ind = (unsigned int)cimg::mod((int)_mp_arg(3),mp.imglist.width());\n        double *const ptrd = &_mp_arg(1) + (dim>1?1:0);\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 '%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 (!siz)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function '%s()': \"\n                                      \"Specified dynamic array #%u contains no elements.\",\n                                      mp.imgout.pixel_type(),s_op,ind);\n        const int siz1 = siz - 1;\n        if (is_pop_heap) { // Heapify-down\n          if (dim==1) cimg::swap(img[0],img[siz1]);\n          else {\n            T *ptr0 = img.data(), *ptr1 = img.data(0,siz1);\n            cimg_forC(img,c) { cimg::swap(*ptr0,*ptr1); ptr0+=img._height; ptr1+=img._height; }\n          }\n          int index = 0;\n          while (true) {\n            const int child_left = 2*index + 1, child_right = child_left + 1;\n            int smallest = index;\n            if (child_left<siz1 && img[child_left]<img[smallest]) smallest = child_left;\n            if (child_right<siz1 && img[child_right]<img[smallest]) smallest = child_right;\n            if (smallest!=index) {\n              if (dim==1) cimg::swap(img[index],img[smallest]);\n              else {","sourceCodeStart":26251,"sourceCodeEnd":26287,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L26251-L26287","documentation":"When a dynamic-array image passes the shape check but its stored element counter siz is 0, popping/removing an element is impossible, so the parser throws this error. It indicates the dynamic array is empty at the time of the operation.","triggerScenarios":"Calling a pop/heap-removal MP opcode (e.g. 'da_pop(...)' or min-heap removal) on an array initialized with zero elements, or popping more times than elements were pushed.","commonSituations":"Unbalanced push/pop sequences in expression loops; reusing an array image already drained by earlier expressions; logic errors in heap-based algorithms (e.g. dijkstra) draining the queue.","solutions":["Check siz > 0 before popping, e.g. guard the expression with a size test.","Balance da_push and da_pop calls in your loop logic.","Re-initialize the array with da_init when starting a fresh algorithm pass.","Track element counts in host code to avoid draining the array."],"exampleFix":"// before\nimg.fill(\"da_pop(0)\"); // may be empty\n// after\nimg.fill(\"siz>0?da_pop(0):nan\");","handlingStrategy":"validation","validationCode":"double siz = arr ? arr(0, arr.height()-1) : 0;\nif (siz <= 0) throw std::runtime_error(\"dynamic array is empty\");","typeGuard":"bool dynArrayNonEmpty(const CImg<T>& a) { return !a.is_empty() && a(0,a.height()-1) > 0; }","tryCatchPattern":"try { img.fill(popExpr); } catch (const cimg_library::CImgArgumentException& e) { /* array drained; stop popping */ }","preventionTips":["Balance pushes and pops","Track element count in host code","Re-init arrays between algorithm passes"],"tags":["cimg","math-parser","dynamic-array","empty-collection"],"backgroundTag":"empty-result-set","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"}