{"record":{"id":"9e25cb44cdbd9949","repo":"Yalantis/uCrop","slug":"save-cimg-empty-instance-for-file-s","errorCode":null,"errorMessage":"save_cimg(): Empty instance, for file '%s'.","messagePattern":"save_cimg\\(\\): Empty instance, for file '(.+?)'\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":68298,"sourceCode":"                  if (skipye) cimg::fseek(nfile,skipye,SEEK_CUR); \\\n                } \\\n                const unsigned int skipze = (D - 1 - nz1)*W*H*sizeof(Tss); \\\n                if (skipze) cimg::fseek(nfile,skipze,SEEK_CUR); \\\n              } \\\n              const unsigned int skipve = (C - 1 - nc1)*W*H*D*sizeof(Tss); \\\n              if (skipve) cimg::fseek(nfile,skipve,SEEK_CUR); \\\n            } \\\n          } \\\n        } \\\n        saved = true; \\\n      }\n\n      if (!file && !filename)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"save_cimg(): Specified filename is (null).\",\n                                    cimglist_instance);\n      if (is_empty())\n        throw CImgInstanceException(_cimglist_instance\n                                    \"save_cimg(): Empty instance, for file '%s'.\",\n                                    cimglist_instance,\n                                    filename?filename:\"(FILE*)\");\n\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"rb+\");\n      bool saved = false, endian = cimg::endianness();\n      CImg<charT> tmp(256), str_pixeltype(256), str_endian(256);\n      *tmp = *str_pixeltype = *str_endian = 0;\n      unsigned int j, N, W, H, D, C;\n      int i, err;\n      j = 0; while ((i=std::fgetc(nfile))!='\\n' && i!=EOF && j<256) tmp[j++] = (char)i; tmp[j] = 0;\n      err = cimg_sscanf(tmp,\"%u%*c%255[A-Za-z123468_]%*c%255[sA-Za-z_ ]\",&N,str_pixeltype._data,str_endian._data);\n      if (err<2) {\n        if (!file) cimg::fclose(nfile);\n        throw CImgIOException(_cimglist_instance\n                              \"save_cimg(): CImg header not found in file '%s'.\",\n                              cimglist_instance,\n                              filename?filename:\"(FILE*)\");","sourceCodeStart":68280,"sourceCodeEnd":68316,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L68280-L68316","documentation":"save_cimg refuses to write when the CImgList instance itself is empty (zero images or all images zero-sized). It throws CImgInstanceException naming the target file. Writing an empty list would produce a meaningless or unparseable .cimg payload, so it is rejected up front.","triggerScenarios":"Calling save_cimg on a default-constructed CImgList, on a list whose images were all assigned/destroyed, or after load failure left the list empty.","commonSituations":"Chained load->save where the load silently failed; filtering the list down to zero images before saving; forgetting to call assign()/insert() to populate the list.","solutions":["Check list.size() (and per-image dimensions) before saving and populate the list if empty.","Fix the upstream load/generation step that produced an empty list.","Skip the save and log/skip gracefully when the list is legitimately empty."],"exampleFix":"// before\nlist.save_cimg(\"out.cimg\"); // list empty\n// after\nif (list.size() > 0) list.save_cimg(\"out.cimg\");\nelse cimg::warn(\"Nothing to save to out.cimg\");","handlingStrategy":"validation","validationCode":"if (list.size() == 0) { /* skip or populate */ } else list.save_cimg(path);","typeGuard":"bool isSavable(const CImgList<T> &l){ return l.size() > 0; }","tryCatchPattern":"try { list.save_cimg(path); } catch (CImgInstanceException &e) { std::fprintf(stderr, \"empty list: %s\", e.what()); }","preventionTips":["Check list.size() after every load before saving","Ensure load errors are detected rather than silently leaving an empty list","Avoid filtering lists down to zero elements before save"],"tags":["empty-data","image-io","state-error"],"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-17T15:17:12.973Z"}