{"record":{"id":"e8edc043b3fd241d","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-e8edc0","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'draw()': Invalid specified target vector geometry (%d,%d,%d,%d).\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'draw\\(\\)': Invalid specified target vector geometry \\((.+?),(.+?),(.+?),(.+?)\\)\\.\"","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":30163,"sourceCode":"      }\n\n      static double mp_vector_draw(_cimg_math_parser& mp) {\n        double *const ptrd = &_mp_arg(1) + 1;\n        const double *const ptrs = &_mp_arg(7) + 1;\n        const unsigned int\n          sizD = (unsigned int)mp.opcode[2],\n          sizS = (unsigned int)mp.opcode[8];\n        const int\n          w = (int)_mp_arg(3), h = (int)_mp_arg(4), d = (int)_mp_arg(5), s = (int)_mp_arg(6),\n          x = (int)_mp_arg(9), y = (int)_mp_arg(10), z = (int)_mp_arg(11), c = (int)_mp_arg(12);\n        int dx = (int)mp.opcode[13], dy = (int)mp.opcode[14], dz = (int)mp.opcode[15], dc = (int)mp.opcode[16];\n        dx = (unsigned int)dx==~0U?w:(int)_mp_arg(13);\n        dy = (unsigned int)dy==~0U?h:(int)_mp_arg(14);\n        dz = (unsigned int)dz==~0U?d:(int)_mp_arg(15);\n        dc = (unsigned int)dc==~0U?s:(int)_mp_arg(16);\n\n        if (w<=0 || h<=0 || d<=0 || s<=0)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'draw()': \"\n                                      \"Invalid specified target vector geometry (%d,%d,%d,%d).\",\n                                      mp.imgin.pixel_type(),w,h,d,s);\n        if (sizD<(ulongT)w*h*d*s)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'draw()': \"\n                                      \"Target vector (%lu values) and its specified target geometry (%d,%d,%d,%d) \"\n                                      \"(%lu values) do not match.\",\n                                      mp.imgin.pixel_type(),sizD,w,h,d,s,(ulongT)w*h*d*s);\n        if (dx<=0 || dy<=0 || dz<=0 || dc<=0)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'draw()': \"\n                                      \"Invalid specified sprite geometry (%d,%d,%d,%d).\",\n                                      mp.imgin.pixel_type(),dx,dy,dz,dc);\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 sprite geometry (%d,%d,%d,%d) \"\n                                      \"(%lu values) do not match.\",\n                                      mp.imgin.pixel_type(),sizS,dx,dy,dz,dc,(ulongT)dx*dy*dz*dc);\n\n        CImg<doubleT> D(ptrd,w,h,d,s,true);","sourceCodeStart":30145,"sourceCodeEnd":30181,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L30145-L30181","documentation":"The math parser 'draw()' function renders into a target vector interpreted with a specified 4D geometry (w,h,d,s). It first validates that all four dimensions are strictly positive; if any is <= 0, a CImgArgumentException reports the invalid target geometry before checking capacity.","triggerScenarios":"draw(...,w,h,d,s,...) in a math expression where one of the geometry arguments (from _mp_arg(9..12) or defaults) evaluates to zero or negative — e.g. a dimension variable computed as 0, or the ~0U sentinel handling leaving w=0 when the caller passed 0 explicitly.","commonSituations":"Computing target geometry from empty/failed upstream results (a size-0 vector); typos swapping arguments so a coordinate lands in a dimension slot; uninitialized math variables defaulting to 0.","solutions":["Ensure all four target dimensions are > 0 in the expression (e.g. max(1, expr)).","Pass the geometry of the destination vector directly (its actual w,h,d,s) rather than computed values.","Fix argument ordering so dimensions and coordinates are not swapped.","Check upstream computations that produced an empty (0-sized) result before drawing.","Catch CImgArgumentException and report the requested geometry for diagnosis."],"exampleFix":"// before: draw(T, ..., 0, H, D, S)\n// after:  draw(T, ..., W, H, D, S)  // W = vector width","handlingStrategy":"validation","validationCode":"if (w <= 0 || h <= 0 || d <= 0 || s <= 0)\n  throw std::runtime_error(\"draw() target geometry must be positive\");","typeGuard":null,"tryCatchPattern":"try { img.evaluate(drawExpr); } catch (const CImgArgumentException& e) { log(\"draw() bad geometry: \" << e.what()); }","preventionTips":["Take w,h,d,s directly from the destination vector's actual dimensions","Guard against empty upstream results producing 0-sized geometry","Check argument ordering so dims are not replaced by coordinates"],"tags":["cimg","math-parser","invalid-argument-value"],"backgroundTag":"invalid-argument-value","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"}