Yalantis/uCrop · error · CImgArgumentException
load_analyze(): Specified filename is (null).
Error message
load_analyze(): Specified filename is (null).
What it means
load_analyze() delegates to _load_analyze(), which accepts either an open FILE* or a filename. If both are null there is nothing to read from, so it throws a CImgArgumentException. Passing only a null filename while file is also null is the rejected condition.
Solutions
- Supply a non-null filename (e.g. pointing at the .hdr/.img Analyze file).
- Alternatively pass an already-open std::FILE* instead of a filename.
- Guard the call: check the path is non-null and non-empty before invoking.
Example fix
// before
img.load_analyze(NULL);
// after
const char *hdr = getenv("ANALYZE_HDR");
if (hdr) img.load_analyze(hdr);
else throw std::runtime_error("ANALYZE_HDR not set"); Defensive patterns
Strategy: validation
Validate before calling
if (!filename || !*filename) throw std::invalid_argument("load_analyze requires a filename or open FILE*");
img.load_analyze(filename, voxelSize); Type guard
bool validAnalyzeTarget(std::FILE *f, const char *name) { return f != nullptr || (name != nullptr && *name != '\0'); } Try / catch
try { img.load_analyze(hdrPath); }
catch (CImgArgumentException &e) { log("no file or filename given to load_analyze"); } Prevention
- Always pass either an open FILE* or a non-null filename
- Resolve .hdr paths before calling
- Centralize path resolution with null checks
When it happens
Trigger: img.load_analyze((std::FILE*)0, NULL), or calling load_analyze(filename) with filename == NULL (no FILE* supplied).
Common situations: Path variables that failed to initialize (null from getenv/config), or generic loader wrappers that forward an empty optional filename.
Related errors
- cimg::ftype(): Specified filename is (null).
- cimg::load_network(): Specified destination string is…
- cimg::load_network(): Specified URL is (null).
- load_ascii(): Specified filename is (null).
- load_bmp(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/607372bb3b1758ed.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:58390
//! Load image from an ANALYZE7.5/NIFTI file \newinstance.
static CImg<T> get_load_analyze(const char *const filename, float *const voxel_size=0) {
return CImg<T>().load_analyze(filename,voxel_size);
}
//! Load image from an ANALYZE7.5/NIFTI file \overloading.
CImg<T>& load_analyze(std::FILE *const file, float *const voxel_size=0) {
return _load_analyze(file,0,voxel_size);
}
//! Load image from an ANALYZE7.5/NIFTI file \newinstance.
static CImg<T> get_load_analyze(std::FILE *const file, float *const voxel_size=0) {
return CImg<T>().load_analyze(file,voxel_size);
}
CImg<T>& _load_analyze(std::FILE *const file, const char *const filename, float *const voxel_size=0) {
if (!file && !filename)
throw CImgArgumentException(_cimg_instance
"load_analyze(): Specified filename is (null).",
cimg_instance);
std::FILE *nfile_header = 0, *nfile = 0;
if (!file) {
CImg<charT> body(1024);
const char *const ext = cimg::split_filename(filename,body);
const unsigned int len = (unsigned int)std::strlen(body);
if (!cimg::strcasecmp(ext,"hdr")) { // File is an Analyze header file
nfile_header = cimg::fopen(filename,"rb");
cimg_snprintf(body._data + len,body._width - len,".img");
nfile = cimg::fopen(body,"rb");
} else if (!cimg::strcasecmp(ext,"img")) { // File is an Analyze data file
nfile = cimg::fopen(filename,"rb");
cimg_snprintf(body._data + len,body._width - len,".hdr");
nfile_header = cimg::fopen(body,"rb");
} else nfile_header = nfile = cimg::fopen(filename,"rb"); // File is a Niftii file
} else nfile_header = nfile = file; // File is a Niftii fileView on GitHub (pinned to f788b534b4)