Yalantis/uCrop · error · CImgArgumentException
load(): Specified filename is (null).
Error message
load(): Specified filename is (null).
What it means
CImg<T>::load(filename) loads an image from disk or network, dispatching on the filename extension. A null filename pointer cannot be inspected, so the method immediately throws CImgArgumentException before attempting any I/O.
Source
Thrown at ucrop/src/main/jni/CImg.h:56447
}
}
disp._normalization = old_normalization;
if (x1>=0 && x1<x0) cimg::swap(x0,x1);
if (y1<y0) cimg::swap(y0,y1);
disp.set_key(okey);
return CImg<intT>(4,1,1,1,x0,y0,x1>=0?x1 + (int)one:-1,y1);
}
//! Load image from a file.
/**
\param filename Filename, as a C-string.
\note The extension of \c filename defines the file format. If no filename
extension is provided, CImg<T>::get_load() will try to load the file as a .cimg or .cimgz file.
**/
CImg<T>& load(const char *const filename) {
if (!filename)
throw CImgArgumentException(_cimg_instance
"load(): Specified filename is (null).",
cimg_instance);
if (!cimg::strncasecmp(filename,"http://",7) || !cimg::strncasecmp(filename,"https://",8)) {
CImg<charT> filename_local(256);
load(cimg::load_network(filename,filename_local));
std::remove(filename_local);
return *this;
}
const char *const ext = cimg::split_filename(filename);
const unsigned int omode = cimg::exception_mode();
cimg::exception_mode(0);
bool is_loaded = true;
try {
#ifdef cimg_load_plugin
cimg_load_plugin(filename);
#endifView on GitHub (pinned to f788b534b4)
Solutions
- Check for null before calling: if (filename) img.load(filename);
- Ensure the filename string is initialized/allocated before the call.
- Load into a std::string first, then pass .c_str() so it can never be null.
Example fix
// before
const char* filename = getenvOptional("IMG"); // may be NULL
img.load(filename);
// after
const char* env = getenvOptional("IMG");
if (env) img.load(env); Defensive patterns
Strategy: validation
Validate before calling
if (!filename || !*filename) {
std::cerr << "No filename provided for load" << std::endl;
return;
}
img.load(filename); Type guard
bool hasFilename(const char* f) { return f != nullptr && f[0] != '\0'; } Try / catch
try {
img.load(filename);
} catch (const cimg_library::CImgArgumentException& e) {
std::cerr << "load() rejected arguments: " << e.what() << std::endl;
} Prevention
- Store filenames in std::string and pass .c_str() to guarantee non-null
- Null-check outputs of config/env lookups before use
- Centralize image loading in one helper that validates the path argument
When it happens
Trigger: Calling load(NULL) directly, or passing a char* filename variable that was never assigned or was freed/set to null after a failed path lookup.
Common situations: Filename built conditionally with one path leaving it null; getConfig-style helpers returning null when a key is missing; passing the result of a failed string conversion straight into load().
Related errors
- load_parrec(): Specified filename is (null).
- load_ascii(): Specified filename is (null).
- load_dlm(): Specified filename is (null).
- load_bmp(): Specified filename is (null).
- load_jpeg(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/55b93fddd27a560b.
Report an issue: GitHub.