{"record":{"id":"4151c8d2892607f8","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-4151c8","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'draw()': Mask vector (%lu values) and specified sprite geometry (%u,%u,%u,%u) (%lu values) do not match.\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'draw\\(\\)': Mask vector \\(%lu values\\) and specified sprite 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":27226,"sourceCode":"        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        }\n        return cimg::type<double>::nan();\n      }\n\n      static double mp_image_h(_cimg_math_parser& mp) {\n        unsigned int ind = (unsigned int)mp.opcode[2];\n        if (ind!=~0U) {\n          if (!mp.imglist.width()) return cimg::type<double>::nan();\n          ind = (unsigned int)cimg::mod((int)_mp_arg(2),mp.imglist.width());\n        }\n        const CImg<T> &img = ind==~0U?mp.imgout:mp.imglist[ind];\n        return (double)img.height();","sourceCodeStart":27208,"sourceCodeEnd":27244,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L27208-L27244","documentation":"When draw() is called with an opacity-mask vector, the mask must contain at least dx*dy*dz values (one per sprite spatial position). This error is thrown when the mask vector length (sizM) is smaller than the sprite's spatial geometry requires.","triggerScenarios":"Calling draw() with a mask argument (opcode[13] set) whose vector size sizM < dx*dy*dz for the sprite geometry in use.","commonSituations":"Reusing a mask computed for a smaller sprite; geometry defaults changed because the target image was resized; mask and sprite generated in separate steps with inconsistent dimensions.","solutions":["Regenerate the mask so it has at least dx*dy*dz values matching the sprite geometry.","Shrink the sprite geometry (dx,dy,dz) to fit the available mask values.","Remove the mask argument if uniform opacity is sufficient.","Compute mask size from the same variables used for geometry to keep them in sync."],"exampleFix":"// before: mask sized for 4x4 sprite but geometry is 8x8\n draw(#0,sprite,8,8,1,3,x,y,z,c,opacity,mask64)\n// after: mask sized to 8x8\n draw(#0,sprite,8,8,1,3,x,y,z,c,opacity,mask256)","handlingStrategy":"validation","validationCode":"// Ensure the mask covers the sprite's spatial extent before draw()\nfunction checkMask(sizM, dx, dy, dz) { if (sizM < dx * dy * dz) throw new Error('mask has ' + sizM + ' values, needs ' + dx * dy * dz); }","typeGuard":"function maskCoversSprite(sizM, dx, dy, dz) { return sizM >= dx * dy * dz; }","tryCatchPattern":"try { evalMath(drawExpr); } catch (e) { if (String(e).includes('Mask vector') && String(e).includes('do not match')) { regenerateMask(); retry(); } else throw e; }","preventionTips":["Generate mask and sprite geometry from the same variables","Regenerate masks whenever sprite geometry changes","Skip the mask argument when uniform opacity suffices"],"tags":["cimg","math-parser","draw","mask","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"}