{"record":{"id":"21982b39da0b82ef","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-21982b","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'draw()': Sprite vector (%lu values) and its specified geometry (%u,%u,%u,%u) (%lu values) do not match.\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'draw\\(\\)': Sprite vector \\(%lu values\\) and its specified geometry \\(%u,%u,%u,%u\\) \\(%lu values\\) do not match\\.\"","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":27215,"sourceCode":"        unsigned int ind = (unsigned int)mp.opcode[3];\n        if (ind!=~0U) {\n          if (!mp.imglist.width()) return cimg::type<double>::nan();\n          ind = (unsigned int)cimg::mod((int)_mp_arg(3),mp.imglist.width());\n        }\n        CImg<T> &img = ind==~0U?mp.imgout:mp.imglist[ind];\n        unsigned int\n          dx = (unsigned int)mp.opcode[8],\n          dy = (unsigned int)mp.opcode[9],\n          dz = (unsigned int)mp.opcode[10],\n          dc = (unsigned int)mp.opcode[11];\n        dx = dx==~0U?img._width:(unsigned int)_mp_arg(8);\n        dy = dy==~0U?img._height:(unsigned int)_mp_arg(9);\n        dz = dz==~0U?img._depth:(unsigned int)_mp_arg(10);\n        dc = dc==~0U?img._spectrum:(unsigned int)_mp_arg(11);\n\n        const ulongT sizS = mp.opcode[2];\n        if (sizS<(ulongT)dx*dy*dz*dc)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'draw()': \"\n                                      \"Sprite vector (%lu values) and its specified geometry (%u,%u,%u,%u) \"\n                                      \"(%lu values) do not match.\",\n                                      mp.imgin.pixel_type(),sizS,dx,dy,dz,dc,(ulongT)dx*dy*dz*dc);\n        const CImg<doubleT> S(&_mp_arg(1) + 1,dx,dy,dz,dc,true);\n        const float opacity = (float)_mp_arg(12);\n\n        if (img._data) {\n          if (mp.opcode[13]!=~0U) { // Opacity mask specified\n            const ulongT sizM = mp.opcode[14];\n            if (sizM<(ulongT)dx*dy*dz)\n              throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'draw()': \"\n                                          \"Mask vector (%lu values) and specified sprite geometry (%u,%u,%u,%u) \"\n                                          \"(%lu values) do not match.\",\n                                          mp.imgin.pixel_type(),sizS,dx,dy,dz,dc,(ulongT)dx*dy*dz*dc);\n            const CImg<doubleT> M(&_mp_arg(13) + 1,dx,dy,dz,(unsigned int)(sizM/(dx*dy*dz)),true);\n            img.draw_image(x,y,z,c,S,M,opacity,(float)_mp_arg(15));\n          } else img.draw_image(x,y,z,c,S,opacity);\n        }","sourceCodeStart":27197,"sourceCodeEnd":27233,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L27197-L27233","documentation":"The math parser's draw() function interprets a sprite vector as an image with geometry (dx,dy,dz,dc) specified via arguments/defaults from the target image. This error is thrown when the sprite vector holds fewer values (sizS) than the requested geometry requires, i.e. the geometry would read past the vector's data.","triggerScenarios":"Calling draw() with explicit or default dx,dy,dz,dc whose product dx*dy*dz*dc exceeds the sprite vector's length (mp.opcode[2] values).","commonSituations":"Hand-editing geometry arguments in a draw() expression; target image resized so defaults (from img dimensions) no longer fit the sprite vector; copying a draw() call between expressions with different vector sizes.","solutions":["Enlarge the sprite vector so it contains at least dx*dy*dz*dc values (e.g. via input/insert of the right length).","Reduce the geometry arguments (dx,dy,dz,dc) to fit within the vector size.","Use default geometry derived from the sprite vector itself instead of explicit dimensions.","Verify vector length with a size check before draw()."],"exampleFix":"// before: geometry larger than vector (10 values vs 2x2x1x3=12 needed)\n draw(#0,vec[10],2,2,1,3,...)\n// after: provide full 12-value vector\n draw(#0,vec12,2,2,1,3,...)","handlingStrategy":"validation","validationCode":"// Ensure the sprite vector can fill the requested geometry before draw()\nfunction checkSprite(sizS, dx, dy, dz, dc) { const need = dx * dy * dz * dc; if (sizS < need) throw new Error('sprite has ' + sizS + ' values, geometry needs ' + need); }","typeGuard":"function spriteFitsGeometry(sizS, dx, dy, dz, dc) { return sizS >= dx * dy * dz * dc; }","tryCatchPattern":"try { evalMath(drawExpr); } catch (e) { if (String(e).includes(\"Function 'draw()'\") && String(e).includes('do not match')) { console.error('sprite/geometry mismatch:', e.message); } else throw e; }","preventionTips":["Derive geometry from the vector length (or vice versa) from one source of truth","Recompute defaults after resizing the target image","Assert vector sizes at build time in generated expressions"],"tags":["cimg","math-parser","draw","shape-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"}