{"record":{"id":"c17fbc81edbe0c12","repo":"Yalantis/uCrop","slug":"cimg-invalid-construction-request-of-a-shared-i","errorCode":null,"errorMessage":"CImg(): Invalid construction request of a shared instance from a CImg<%s> image (%u,%u,%u,%u,%p) (pixel types are different).","messagePattern":"CImg\\(\\): Invalid construction request of a shared instance from a CImg<(.+?)> image \\(%u,%u,%u,%u,%p\\) \\(pixel types are different\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":13466,"sourceCode":"    /**\n       Construct a new image instance with pixels of type \\c T, as a copy of an existing \\c CImg<t> instance,\n       while forcing the shared state of the constructed copy.\n       \\param img Input image to copy.\n       \\param is_shared Tells about the shared state of the constructed copy.\n       \\note\n       - Similar to CImg(const CImg<t>&), except that it allows to decide the shared state of\n         the constructed image, which does not depend anymore on the shared state of the input image \\c img:\n         - If \\c is_shared is \\c true, the constructed copy will share its pixel buffer with the input image \\c img.\n           For that case, the pixel types \\c T and \\c t \\e must be the same.\n         - If \\c is_shared is \\c false, the constructed copy will allocate its own pixel buffer, whether the input\n           image \\c img is shared or not.\n       - A \\c CImgArgumentException is thrown when a shared copy is requested with different pixel types \\c T and \\c t.\n    **/\n    template<typename t>\n    CImg(const CImg<t>& img, const bool is_shared):_is_shared(false) {\n      if (is_shared) {\n        _width = _height = _depth = _spectrum = 0; _data = 0;\n        throw CImgArgumentException(_cimg_instance\n                                    \"CImg(): Invalid construction request of a shared instance from a \"\n                                    \"CImg<%s> image (%u,%u,%u,%u,%p) (pixel types are different).\",\n                                    cimg_instance,\n                                    CImg<t>::pixel_type(),img._width,img._height,img._depth,img._spectrum,img._data);\n      }\n      const size_t siz = (size_t)img.size();\n      if (img._data && siz) {\n        _width = img._width; _height = img._height; _depth = img._depth; _spectrum = img._spectrum;\n        try { _data = new T[siz]; } catch (...) {\n          _width = _height = _depth = _spectrum = 0; _data = 0;\n          throw CImgInstanceException(_cimg_instance\n                                      \"CImg(): Failed to allocate memory (%s) for image (%u,%u,%u,%u).\",\n                                      cimg_instance,\n                                      cimg::strbuffersize(sizeof(T)*img._width*img._height*img._depth*img._spectrum),\n                                      img._width,img._height,img._depth,img._spectrum);\n        }\n        const t *ptrs = img._data; cimg_for(*this,ptrd,T) *ptrd = (T)*(ptrs++);\n      } else { _width = _height = _depth = _spectrum = 0; _data = 0; }","sourceCodeStart":13448,"sourceCodeEnd":13484,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L13448-L13484","documentation":"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.","triggerScenarios":"Thrown at ucrop/src/main/jni/CImg.h:13466 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}