Yalantis/uCrop · error · CImgArgumentException
CImg(): Invalid construction request of a shared instance…
Error message
CImg(): Invalid construction request of a shared instance from a CImg<%s> image (%u,%u,%u,%u,%p) (pixel types are different).
What it means
Thrown when constructing a shared CImg<T> copy from a CImg<t> source with a different pixel type t != T: sharing requires identical pixel buffers, so the shared-state constructor cannot alias memory across differing element types and reports the mismatched instance dimensions and pointer.
Solutions
- Use the same pixel type on both sides, e.g. construct CImg<float> from another CImg<float> with is_shared=true
- If types must differ, drop the shared requirement and use a regular copy constructor, which converts pixel values
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at ucrop/src/main/jni/CImg.h:13466 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/c17fbc81edbe0c12.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:13466
/**
Construct a new image instance with pixels of type \c T, as a copy of an existing \c CImg<t> instance,
while forcing the shared state of the constructed copy.
\param img Input image to copy.
\param is_shared Tells about the shared state of the constructed copy.
\note
- Similar to CImg(const CImg<t>&), except that it allows to decide the shared state of
the constructed image, which does not depend anymore on the shared state of the input image \c img:
- If \c is_shared is \c true, the constructed copy will share its pixel buffer with the input image \c img.
For that case, the pixel types \c T and \c t \e must be the same.
- If \c is_shared is \c false, the constructed copy will allocate its own pixel buffer, whether the input
image \c img is shared or not.
- A \c CImgArgumentException is thrown when a shared copy is requested with different pixel types \c T and \c t.
**/
template<typename t>
CImg(const CImg<t>& img, const bool is_shared):_is_shared(false) {
if (is_shared) {
_width = _height = _depth = _spectrum = 0; _data = 0;
throw CImgArgumentException(_cimg_instance
"CImg(): Invalid construction request of a shared instance from a "
"CImg<%s> image (%u,%u,%u,%u,%p) (pixel types are different).",
cimg_instance,
CImg<t>::pixel_type(),img._width,img._height,img._depth,img._spectrum,img._data);
}
const size_t siz = (size_t)img.size();
if (img._data && siz) {
_width = img._width; _height = img._height; _depth = img._depth; _spectrum = img._spectrum;
try { _data = new T[siz]; } catch (...) {
_width = _height = _depth = _spectrum = 0; _data = 0;
throw CImgInstanceException(_cimg_instance
"CImg(): Failed to allocate memory (%s) for image (%u,%u,%u,%u).",
cimg_instance,
cimg::strbuffersize(sizeof(T)*img._width*img._height*img._depth*img._spectrum),
img._width,img._height,img._depth,img._spectrum);
}
const t *ptrs = img._data; cimg_for(*this,ptrd,T) *ptrd = (T)*(ptrs++);
} else { _width = _height = _depth = _spectrum = 0; _data = 0; }View on GitHub (pinned to f788b534b4)