{"record":{"id":"b5fe38bd309a340b","repo":"Yalantis/uCrop","slug":"get-shared-slices-invalid-request-of-a-shared-m","errorCode":null,"errorMessage":"get_shared_slices(): Invalid request of a shared-memory subset (0->%u,0->%u,%u->%u,%u).","messagePattern":"get_shared_slices\\(\\): Invalid request of a shared-memory subset \\(0->%u,0->%u,%u->%u,%u\\)\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":41650,"sourceCode":"    }\n\n    //! Return a shared-memory image referencing one row of the image instance \\const.\n    const CImg<T> get_shared_row(const unsigned int y0, const unsigned int z0=0, const unsigned int c0=0) const {\n      return get_shared_rows(y0,y0,z0,c0);\n    }\n\n    //! Return a shared memory image referencing a range of slices of the image instance.\n    /**\n       \\param z0 Z-coordinate of the starting slice.\n       \\param z1 Z-coordinate of the ending slice.\n       \\param c0 C-coordinate.\n    **/\n    CImg<T> get_shared_slices(const unsigned int z0, const unsigned int z1, const unsigned int c0=0) {\n      const ulongT\n        beg = (ulongT)offset(0,0,z0,c0),\n        end = (ulongT)offset(0,0,z1,c0);\n      if (beg>end || beg>=size() || end>=size())\n        throw CImgArgumentException(_cimg_instance\n                                    \"get_shared_slices(): Invalid request of a shared-memory subset \"\n                                    \"(0->%u,0->%u,%u->%u,%u).\",\n                                    cimg_instance,\n                                    _width - 1,_height - 1,z0,z1,c0);\n      return CImg<T>(_data + beg,_width,_height,z1 - z0 + 1,1,true);\n    }\n\n    //! Return a shared memory image referencing a range of slices of the image instance \\const.\n    const CImg<T> get_shared_slices(const unsigned int z0, const unsigned int z1, const unsigned int c0=0) const {\n      const ulongT\n        beg = (ulongT)offset(0,0,z0,c0),\n        end = (ulongT)offset(0,0,z1,c0);\n      if (beg>end || beg>=size() || end>=size())\n        throw CImgArgumentException(_cimg_instance\n                                    \"get_shared_slices(): Invalid request of a shared-memory subset \"\n                                    \"(0->%u,0->%u,%u->%u,%u).\",\n                                    cimg_instance,\n                                    _width - 1,_height - 1,z0,z1,c0);","sourceCodeStart":41632,"sourceCodeEnd":41668,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L41632-L41668","documentation":"CImg<T>::get_shared_slices() returns a shared-memory image referencing slices z0..z1 of channel c0. It throws CImgArgumentException when beg > end, beg >= size(), or end >= size(), meaning the slice range is inverted or lies outside the instance's memory.","triggerScenarios":"Calling img.get_shared_slices(z0,z1,c0) with z0 > z1, z1 >= img.depth(), or c0 >= img.spectrum(), so the end offset exceeds the total pixel count.","commonSituations":"Treating a 2D image (depth==1) as volumetric and requesting slice ranges; count-vs-index confusion (depth instead of depth-1); a channel index that is valid for RGBA data but not for the loaded grayscale image.","solutions":["Ensure z0 <= z1 and z1 < img.depth(); clamp to depth-1 before the call.","Check c0 < img.spectrum(); select a valid channel or append channels if needed.","For 2D images (depth 1), call get_shared_slices(0,0,c0) or use get_shared_rows instead.","Re-derive z indices from img.depth() at call time rather than cached geometry."],"exampleFix":"// before\nCImg<float> sl = vol.get_shared_slices(0, vol.depth());   // exclusive end\n// after\nunsigned z1c = std::min(z1, vol.depth() - 1);\nCImg<float> sl = vol.get_shared_slices(z0, z1c, c);","handlingStrategy":"validation","validationCode":"bool ok = z0 <= z1 && z1 < img.depth() && c0 < img.spectrum();","typeGuard":null,"tryCatchPattern":"try { auto sl = img.get_shared_slices(z0, z1, c); }\ncatch (CImgArgumentException& e) { /* clamp z1 to depth-1 and retry */ }","preventionTips":["Handle 2D images (depth==1) with slice index 0","Clamp slice bounds to depth-1","Confirm channel index < spectrum"],"tags":["cimg","shared-memory","bounds-check"],"backgroundTag":"index-out-of-bounds","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"}