{"record":{"id":"0761cc3b52a5d026","repo":"Yalantis/uCrop","slug":"save-cimg-failed-to-save-compressed-data-for-fi","errorCode":null,"errorMessage":"save_cimg(): Failed to save compressed data for file '%s', saving them uncompressed.","messagePattern":"save_cimg\\(\\): Failed to save compressed data for file '(.+?)', saving them uncompressed\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":68199,"sourceCode":"              cbuf = new Bytef[csiz];\n              failed_to_compress = (bool)compress(cbuf,&csiz,(Bytef*)buf,siz);\n              if (!failed_to_compress) {\n                std::fprintf(nfile,\" #%lu\\n\",csiz);\n                cimg::fwrite(cbuf,csiz,nfile);\n              }\n              delete[] buf;\n            } else { // Non-boolean data\n              const ulongT siz = sizeof(T)*ref.size();\n              csiz = siz + siz/100 + 16;\n              cbuf = new Bytef[csiz];\n              failed_to_compress = (bool)compress(cbuf,&csiz,(Bytef*)ref._data,siz);\n              if (!failed_to_compress) {\n                std::fprintf(nfile,\" #%lu\\n\",csiz);\n                cimg::fwrite(cbuf,csiz,nfile);\n              }\n            }\n            if (failed_to_compress)\n              cimg::warn(_cimglist_instance\n                         \"save_cimg(): Failed to save compressed data for file '%s', saving them uncompressed.\",\n                         cimglist_instance,\n                         filename?filename:\"(FILE*)\");\n            delete[] cbuf;\n#endif\n          }\n          if (failed_to_compress) { // Write non-compressed\n            std::fputc('\\n',nfile);\n            if (is_bool) { // Boolean data (bitwise)\n              ulongT siz;\n              const unsigned char *const buf = ref._bool2uchar(siz,false);\n              cimg::fwrite(buf,siz,nfile);\n              delete[] buf;\n            } else cimg::fwrite(ref._data,ref.size(),nfile); // Non-boolean data\n          }\n        } else std::fputc('\\n',nfile);\n      }\n      if (!file) cimg::fclose(nfile);","sourceCodeStart":68181,"sourceCodeEnd":68217,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L68181-L68217","documentation":"During save_cimg() of compressed data (zlib enabled), the deflate compression of a tile/strip failed (failed_to_compress set). The library warns and writes the data uncompressed for that item instead, so the save still completes.","triggerScenarios":"cimg_use_zlob... i.e. zlib-enabled build where compress()/deflate returns Z_* error — typically out-of-memory for the compression buffer, or zlib returning an error on very large buffers; internal buffer allocation failure for cbuf.","commonSituations":"Very large images exhausting memory during compression; corrupted/limited zlib installation; resource-constrained embedded environments (Android NDK builds of uCrop).","solutions":["Check available memory; compress smaller images or reduce resolution before saving","Verify the zlib library is correctly built/linked (zlibVersion() sanity check)","Save uncompressed (is_compressed=false) if compression keeps failing","Free other allocations before saving to avoid compress() failing on allocation"],"exampleFix":"// before\nimages.save_cimg(\"out.cimgz\", true);\n// after\ntry {\n  images.save_cimg(\"out.cimgz\", true);\n} catch (...) { /* may have fallen back to uncompressed */ }\n// or avoid compression entirely:\nimages.save_cimg(\"out.cimg\", false);","handlingStrategy":"fallback","validationCode":"// preflight zlib\nif (zlibVersion() == nullptr) { /* zlib broken: save uncompressed */ images.save_cimg(\"out.cimg\", false); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure adequate memory for compression buffers","Sanity-check zlib linkage (zlibVersion) at startup","Fall back to uncompressed saving when compression is unreliable"],"tags":["cimg","zlib","compression","memory"],"backgroundTag":"file-write-failed","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"}