Yalantis/uCrop · warning
cimg::fclose(): Error code
Error message
cimg::fclose(): Error code %d returned during file closing.
What it means
cimg::fclose() wraps std::fclose() and warns when the close call returns a nonzero error code, meaning buffered data may not have been flushed and the file was not closed properly. It is a non-fatal diagnostic; the return code is still propagated to the caller.
Solutions
- Check the return value of cimg::fclose() and treat nonzero as a save failure (the file may be corrupt)
- Check free disk space and medium health on the target volume
- Check for prior write errors (ferror) before closing, and retry the save
- On Windows, ensure no other process holds the file open
Example fix
// before
img.save("out.bmp");
cimg::fclose(file);
// after
if (cimg::fclose(file) != 0) {
std::fprintf(stderr, "file close failed - output may be incomplete\n");
} Defensive patterns
Strategy: try-catch
Validate before calling
// before closing
if (file && !std::ferror(file)) {
int r = cimg::fclose(file);
if (r != 0) fprintf(stderr, "close failed (%d), output may be corrupt\n", r);
} Prevention
- Always check cimg::fclose's return value after saving
- Check disk free space before large writes
- Detect earlier write failures with ferror() so failed saves are retried
When it happens
Trigger: Calling cimg::fclose() on a real FILE* (not stdin/stdout/null) when the underlying close/flush fails — e.g. disk full, medium removed, or the stream is already in an error state after a prior failed write.
Common situations: Writing large images to a full disk or removable drive; network/USB storage dropping mid-write; ignoring earlier write errors so fclose also fails at flush time.
Related errors
- cimg::fclose(): Specified file is (null).
- cimg::fempty(): Specified filename is (null).
- cimg::fopen(): Failed to open file
- cimg::fopen(): File ' ', specified mode is (null).
- cimg::fopen(): Specified file path is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/36d68d74ccb732f2.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:7584
#endif
} else res = cimg::std_fopen(path,mode);
if (!res) throw CImgIOException("cimg::fopen(): Failed to open file '%s' with mode '%s'.",
path,mode);
return res;
}
//! Close a file.
/**
\param file File to close.
\return \c 0 if file has been closed properly, something else otherwise.
\note Same as <tt>std::fclose()</tt> but display a warning message if
the file has not been closed properly.
**/
inline int fclose(std::FILE *file) {
if (!file) { warn("cimg::fclose(): Specified file is (null)."); return 0; }
if (file==cimg::_stdin(false) || file==cimg::_stdout(false)) return 0;
const int errn = std::fclose(file);
if (errn!=0) warn("cimg::fclose(): Error code %d returned during file closing.",
errn);
return errn;
}
//! Version of 'fseek()' that supports >=64bits offsets everywhere (for Windows).
inline int fseek(FILE *stream, cimg_long offset, int origin) {
#if defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
return _fseeki64(stream,(__int64)offset,origin);
#else
return std::fseek(stream,offset,origin);
#endif
}
//! Version of 'ftell()' that supports >=64bits offsets everywhere (for Windows).
inline cimg_long ftell(FILE *stream) {
#if defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
return (cimg_long)_ftelli64(stream);
#elseView on GitHub (pinned to f788b534b4)