Yalantis/uCrop · error · CImgArgumentException
save_rgb(): Specified filename is (null).
Error message
save_rgb(): Specified filename is (null).
What it means
Raised by _save_rgb()'s guard when both the FILE* and filename arguments are null, meaning no output destination was specified for the RGB data (the library prints the missing filename as '(null)'). It is a generic validation check that fires before any bytes are written; give the call a valid filename or open stream.
Solutions
- Pass a non-null filename to save_rgb()
- Pass a valid opened FILE* instead of a null one
- Validate the destination path/FILE* before invoking save_rgb()
Example fix
// before
img.save_rgb(name ? name.c_str() : NULL);
// after
if (name.empty()) throw std::invalid_argument("rgb output path required");
img.save_rgb(name.c_str()); Defensive patterns
Strategy: validation
Validate before calling
if (!file && (!filename || !*filename)) throw std::invalid_argument("save_rgb requires a filename or FILE*"); Type guard
bool hasDestination(std::FILE *f, const char *name) { return f != NULL || (name != NULL && name[0] != '\0'); } Try / catch
try { img.save_rgb(path.c_str()); } catch (CImgArgumentException &e) { /* handle */ } Prevention
- Check fopen() results
- Never pass literal NULL/0 as filename in raw-format saves
- Sanitize CLI/config paths before use
When it happens
Trigger: Calling save_rgb((std::FILE*)0); passing a null FILE* from a failed fopen; generic save() dispatch reaching the rgb path with a null name.
Common situations: Unchecked fopen result in raw-dump utilities; empty filename variables in batch conversion scripts; incorrect overload selection passing 0 as filename.
Related errors
- save_pfm(): Specified filename is (null).
- save_pnk(): Specified filename is (null).
- save_pnm(): Specified filename is (null).
- save_rgba(): Specified filename is (null).
- load_cimg(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/6554779426a77a82.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:62569
return *this;
}
//! Save image as a RGB file.
/**
\param filename Filename, as a C-string.
**/
const CImg<T>& save_rgb(const char *const filename) const {
return _save_rgb(0,filename);
}
//! Save image as a RGB file \overloading.
const CImg<T>& save_rgb(std::FILE *const file) const {
return _save_rgb(file,0);
}
const CImg<T>& _save_rgb(std::FILE *const file, const char *const filename) const {
if (!file && !filename)
throw CImgArgumentException(_cimg_instance
"save_rgb(): Specified filename is (null).",
cimg_instance);
if (is_empty()) { cimg::fempty(file,filename); return *this; }
if (_spectrum!=3)
cimg::warn(_cimg_instance
"save_rgb(): image instance has not exactly 3 channels, for file '%s'.",
cimg_instance,
filename?filename:"(FILE*)");
std::FILE *const nfile = file?file:cimg::fopen(filename,"wb");
const ulongT wh = (ulongT)_width*_height;
unsigned char *const buffer = new unsigned char[3*wh], *nbuffer = buffer;
const T
*ptr1 = data(0,0,0,0),
*ptr2 = _spectrum>1?data(0,0,0,1):0,
*ptr3 = _spectrum>2?data(0,0,0,2):0;
switch (_spectrum) {
case 1 : { // Scalar imageView on GitHub (pinned to f788b534b4)