Yalantis/uCrop · error · CImgArgumentException
load_cimg(): Specified filename is (null).
Error message
load_cimg(): Specified filename is (null).
What it means
CImgList::load_cimg() requires either a filename or an open FILE*; if both are null it throws CImgArgumentException before doing any I/O (CImg.h:66782). It is a programming/API-misuse guard, not a file problem.
Solutions
- Check the path string is non-empty and pass it only when non-null.
- If reading from memory, open the stream yourself: load_cimg("file.cimg") or pass an std::FILE* from fopen.
- Fix the upstream code that produced the null/empty path (missing env var, failed config lookup).
Example fix
// before
const char* path = getenv("CIMG_DATA"); // may be NULL
imgs.load_cimg(path);
// after
const char* path = getenv("CIMG_DATA");
if (path && *path) imgs.load_cimg(path);
else throw std::invalid_argument("CIMG_DATA path not set"); Defensive patterns
Strategy: validation
Validate before calling
bool canLoadCimg(const char* path) { return path != nullptr && *path != '\0'; } Try / catch
if (!canLoadCimg(path))
throw std::invalid_argument("load_cimg: filename must be non-empty");
try {
imgs.load_cimg(path);
} catch (cimg_library::CImgArgumentException& e) {
logError("null path: %s", e.what());
} Prevention
- Guard env/config lookups for null/empty before passing paths into CImg
- In JNI, check jstring for null before GetStringUTFChars
- Never pass c_str() of an empty std::string
- Resolve and log the full path before calling load_cimg
When it happens
Trigger: Calling list.load_cimg(NULL) or load_cimg(std::string().c_str()) where the string is empty, or passing filename=NULL with file=NULL because an earlier path-lookup returned null.
Common situations: A config/env variable holding the dataset path is empty; a JNI layer passing a null jstring converted to nullptr; a failed path join producing an empty string.
Related errors
- atN(): Empty instance.
- atNX(): Empty instance.
- atNXY(): Empty instance.
- atNXYZ(): Empty instance.
- atNXYZC(): Empty instance.
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/2ad8b947e4b219a9.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:66782
} else { \
CImg<Tss> raw; \
for (ulongT to_read = img.size(); to_read; ) { \
raw.assign((unsigned int)std::min(to_read,cimg_iobuffer)); \
cimg::fread(raw._data,raw._width,nfile); \
if (endian!=cimg::endianness()) cimg::invert_endianness(raw._data,raw.size()); \
const Tss *ptrs = raw._data; \
for (ulongT off = (ulongT)raw._width; off; --off) *(ptrd++) = (T)*(ptrs++); \
to_read-=raw._width; \
} \
} \
} \
} \
} \
loaded = true; \
}
if (!filename && !file)
throw CImgArgumentException(_cimglist_instance
"load_cimg(): Specified filename is (null).",
cimglist_instance);
const ulongT cimg_iobuffer = (ulongT)24*1024*1024;
std::FILE *const nfile = file?file:cimg::fopen(filename,"rb");
bool loaded = false, endian = cimg::endianness();
CImg<charT> tmp(256), str_pixeltype(256), str_endian(256);
*tmp = *str_pixeltype = *str_endian = 0;
unsigned int j, N = 0, W, H, D, C;
cimg_uint64 csiz;
int i, err;
do {
j = 0; while ((i=std::fgetc(nfile))!='\n' && i>=0 && j<255) tmp[j++] = (char)i; tmp[j] = 0;
} while (*tmp=='#' && i>=0);
err = cimg_sscanf(tmp,"%u%*c%255[A-Za-z123468_]%*c%255[sA-Za-z_ ]",
&N,str_pixeltype._data,str_endian._data);
if (err<2) {
if (!file) cimg::fclose(nfile);View on GitHub (pinned to f788b534b4)