{"record":{"id":"dadaab8c7e3c6615","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-dadaab","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'resize()': Cannot both fill and resize image (%u,%u,%u,%u) to new dimensions (%u,%u,%u,%u).\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'resize\\(\\)': Cannot both fill and resize image \\(%u,%u,%u,%u\\) to new dimensions \\(%u,%u,%u,%u\\)\\.\"","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":27298,"sourceCode":"      static double mp_image_resize(_cimg_math_parser& mp) {\n        mp_check_list(mp,\"resize\");\n        const unsigned int ind = (unsigned int)cimg::mod((int)_mp_arg(2),mp.imglist.width());\n        cimg::mutex(6);\n        CImg<T> &img = mp.imglist[ind];\n        const double\n          _w = mp.opcode[3]==~0U?-100:_mp_arg(3),\n          _h = mp.opcode[4]==~0U?-100:_mp_arg(4),\n          _d = mp.opcode[5]==~0U?-100:_mp_arg(5),\n          _s = mp.opcode[6]==~0U?-100:_mp_arg(6);\n        const unsigned int\n          w = (unsigned int)(_w>=0?_w:-_w*img.width()/100),\n          h = (unsigned int)(_h>=0?_h:-_h*img.height()/100),\n          d = (unsigned int)(_d>=0?_d:-_d*img.depth()/100),\n          s = (unsigned int)(_s>=0?_s:-_s*img.spectrum()/100),\n          interp = (int)_mp_arg(7);\n        if (mp.is_fill && img._data==mp.imgout._data) {\n          cimg::mutex(6,0);\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'resize()': \"\n                                      \"Cannot both fill and resize image (%u,%u,%u,%u) \"\n                                      \"to new dimensions (%u,%u,%u,%u).\",\n                                      img.pixel_type(),img._width,img._height,img._depth,img._spectrum,w,h,d,s);\n        }\n        const unsigned int\n          boundary = (int)_mp_arg(8);\n        const float\n          cx = (float)_mp_arg(9),\n          cy = (float)_mp_arg(10),\n          cz = (float)_mp_arg(11),\n          cc = (float)_mp_arg(12);\n        img.resize(w,h,d,s,interp,boundary,cx,cy,cz,cc);\n        cimg::mutex(6,0);\n        return cimg::type<double>::nan();\n      }\n\n      static double mp_image_s(_cimg_math_parser& mp) {\n        unsigned int ind = (unsigned int)mp.opcode[2];","sourceCodeStart":27280,"sourceCodeEnd":27316,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L27280-L27316","documentation":"Inside the math parser, resize() cannot operate when the parser is in fill mode (mp.is_fill) and the target image shares its data buffer with the parser's output image (img._data==mp.imgout._data): resizing would reallocate the buffer currently being filled, corrupting parser state. CImg deliberately rejects this combination.","triggerScenarios":"Calling resize(...) on the same image that the enclosing fill/expr expression is writing into (identical data pointer) while is_fill is active — e.g. resize(#0,...) where #0 is the output image of the current math evaluation.","commonSituations":"In-place expressions that both fill and resize the output image; scripts combining fill(...) with resize(...) on the same image index; refactorings that merged two separate pipeline steps into one expression.","solutions":["Split the operation: perform fill(...) and resize(...) as two separate commands/expressions.","Resize a different image index, or copy the data first and resize the copy.","Remove resize() from inside the fill/math-parser expression and apply it after evaluation completes.","Restructure the pipeline so the output image is fully sized before filling."],"exampleFix":"// before: fill and resize entangled on same image\nfill(expr_with_resize(#0,...))\n// after: separate steps\nresize(#0,w,h,d,s,-1); fill(#0,expr_without_resize)","handlingStrategy":"fallback","validationCode":"// Detect the conflicting in-place resize-before-evaluating\nfunction isUnsafeInPlaceResize(targetIndex, fillOutputIndex) { return targetIndex === fillOutputIndex; }","typeGuard":null,"tryCatchPattern":"try { evalMath(expr); } catch (e) { if (String(e).includes(\"Function 'resize()'\") && String(e).includes('Cannot both fill and resize')) { runSplitPipeline(); } else throw e; }","preventionTips":["Never call resize() on the output image inside a fill/expr expression","Split fill and resize into sequential commands","Pre-size the output image before evaluation","Keep math expressions free of buffer-reallocation calls on the evaluated image"],"tags":["cimg","math-parser","resize","invalid-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}