{"record":{"id":"f10edf82de4804e8","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-canno","errorCode":null,"errorMessage":"[cimg_appname_math_parser] CImg<%s>::%s: %s: Cannot crop empty image when some xyzc-coordinates are unspecified, in expression '%s'.","messagePattern":"\\[cimg_appname_math_parser\\] CImg<(.+?)>::(.+?): (.+?): Cannot crop empty image when some xyzc-coordinates are unspecified, in expression '(.+?)'\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":20688,"sourceCode":"                  opcode[6] = (ulongT)mem[opcode[6]];\n                }\n                if (opcode[7]!=(ulongT)~0U) {\n                  _cimg_mp_check_const_scalar((unsigned int)opcode[7],arg1 + 3,3);\n                  opcode[7] = (ulongT)mem[opcode[7]];\n                }\n                _cimg_mp_check_type((unsigned int)opcode[8],arg1 + 4,1,0);\n\n                if (opcode[4]==(ulongT)~0U || opcode[5]==(ulongT)~0U ||\n                    opcode[6]==(ulongT)~0U || opcode[7]==(ulongT)~0U) {\n                  p2 = 0;\n                  if (p1!=~0U) {\n                    _cimg_mp_check_const_scalar(p1,1,1);\n                    p2 = (unsigned int)cimg::mod((int)mem[p1],imglist.width());\n                  }\n                  const CImg<T> &img = p1!=~0U?imglist[p2]:imgin;\n                  if (!img) {\n                    _cimg_mp_strerr;\n                    throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                                \"CImg<%s>::%s: %s: Cannot crop empty image when \"\n                                                \"some xyzc-coordinates are unspecified, in expression '%s'.\",\n                                                pixel_type(),_cimg_mp_calling_function,s_op,s0);\n                  }\n                  if (opcode[4]==(ulongT)~0U) opcode[4] = (ulongT)img._width;\n                  if (opcode[5]==(ulongT)~0U) opcode[5] = (ulongT)img._height;\n                  if (opcode[6]==(ulongT)~0U) opcode[6] = (ulongT)img._depth;\n                  if (opcode[7]==(ulongT)~0U) opcode[7] = (ulongT)img._spectrum;\n                }\n\n                pos = vector((unsigned int)(opcode[4]*opcode[5]*opcode[6]*opcode[7]));\n                CImg<ulongT>::vector((ulongT)mp_image_crop,\n                                     pos,p1, // 1-2: res,#ind\n                                     *opcode,opcode[1],opcode[2],opcode[3], // 3-6: x,y,z,c\n                                     opcode[4],opcode[5],opcode[6],opcode[7], // 7-10: dx,dy,dz,dc\n                                     opcode[8]).move_to(code); // 11: boundary conditions\n\n              } else { // Vector crop","sourceCodeStart":20670,"sourceCodeEnd":20706,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L20670-L20706","documentation":"CImg's math parser (used by expressions like fill, crop, or index-based access) throws this when an expression attempts to crop an image whose instance is empty (zero dimensions) while some x/y/z/c coordinates are left unspecified, so defaults would have to be taken from the image's own dimensions. The parser checks `if (!img)` before resolving unspecified coordinates and aborts with CImgArgumentException rather than producing an undefined crop. It is a defensive guard: an empty image has no geometry to substitute for omitted coordinates.","triggerScenarios":"Calling crop() inside a math expression (e.g. `crop(...)` opcode in an expression like `i(x,y)`-style pipelines or `crop(ind,...)`) on image slot 0 or imglist[p2] that is empty, while omitting one or more of the x/y/z/c arguments so the parser tries to default them from img._width/_height etc. Occurs when imglist.width()>0 but the selected image is a default-constructed empty CImg, or imgin is empty.","commonSituations":"A G'MIC/CImg filter chain where an earlier processing step produced a zero-size image (e.g. a failed threshold or resize to 0); indexing the wrong image list slot whose entry was never assigned; loading an image from a missing/failed source and continuing to crop without checking.","solutions":["Check that the target image is non-empty before evaluating the expression: `if (img && !img.is_empty()) ...`","Verify the image-list index p2 resolves to the intended, populated image (print imglist.size() and img.width()).","Specify all four x/y/z/c coordinates explicitly so the parser does not need to default them from the empty image's geometry.","Debug upstream steps in the expression pipeline that emptied the image (failed load, crop with zero extent)."],"exampleFix":"// before\nimg.crop(10,10); // img may be empty -> parser throws\n// after\nif (!img.is_empty()) img.crop(10,10, x, y, z, c); // or guard upstream load","handlingStrategy":"validation","validationCode":"// before evaluating the expression\nif (img.is_empty()) throw std::runtime_error(\"source image is empty; skip crop expression\");\n// CImg API\ncimg_for(imglist, ptr, T) if (ptr->is_empty()) ... handle ...;","typeGuard":"template<typename T>\nbool is_cropable(const CImg<T>& im) { return !im.is_empty(); }","tryCatchPattern":"try {\n  img.crop(x, y, z, c);\n} catch (const CImgArgumentException& e) {\n  // empty-image crop guard: log and fall back to original image\n  result = img;\n}","preventionTips":["Always check is_empty() after loading/producing an image before further processing","Validate image-list slots are populated before indexing them in expressions","Pass explicit x/y/z/c coordinates instead of relying on defaults","Fail fast when an upstream step yields a zero-size image"],"tags":["cimg","math-parser","empty-image","crop"],"backgroundTag":"empty-required-field","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"}