Yalantis/uCrop · error · CImgArgumentException
load_pfm(): Specified filename is (null).
Error message
load_pfm(): Specified filename is (null).
What it means
This is an argument-contract check in CImg<T>::_load_pfm(): the loader requires either an open FILE* or a non-null filename. If both are null, there is nothing to read from, so it throws CImgArgumentException before touching the file system.
Source
Thrown at ucrop/src/main/jni/CImg.h:57771
//! Load image from a PFM file \newinstance.
static CImg<T> get_load_pfm(const char *const filename) {
return CImg<T>().load_pfm(filename);
}
//! Load image from a PFM file \overloading.
CImg<T>& load_pfm(std::FILE *const file) {
return _load_pfm(file,0);
}
//! Load image from a PFM file \newinstance.
static CImg<T> get_load_pfm(std::FILE *const file) {
return CImg<T>().load_pfm(file);
}
CImg<T>& _load_pfm(std::FILE *const file, const char *const filename) {
if (!file && !filename)
throw CImgArgumentException(_cimg_instance
"load_pfm(): Specified filename is (null).",
cimg_instance);
std::FILE *const nfile = file?file:cimg::fopen(filename,"rb");
char pfm_type;
CImg<charT> item(16384,1,1,1,0);
int W = 0, H = 0, err = 0;
double scale = 0;
while ((err=std::fscanf(nfile,"%16383[^\n]",item.data()))!=EOF && (*item=='#' || !err)) std::fgetc(nfile);
if (cimg_sscanf(item," P%c",&pfm_type)!=1) {
if (!file) cimg::fclose(nfile);
throw CImgIOException(_cimg_instance
"load_pfm(): PFM header not found in file '%s'.",
cimg_instance,
filename?filename:"(FILE*)");
}
while ((err=std::fscanf(nfile," %16383[^\n]",item.data()))!=EOF && (*item=='#' || !err)) std::fgetc(nfile);
if ((err=cimg_sscanf(item," %d %d",&W,&H))<2) {View on GitHub (pinned to f788b534b4)
Solutions
- Pass a valid filename string to load_pfm, e.g. img.load_pfm("scene.pfm").
- Open the file yourself and pass the FILE*: FILE* f=fopen(path,"rb"); img.load_pfm(f).
- Check why the filename is null (failed getenv/lookup) and provide a default or abort early with a clear error.
- Guard the call: if (!path) { report; return; } before invoking the loader.
- Catch CImgArgumentException in calling code that deals with optional paths.
Example fix
// before
const char* path = getenv("HDR_FILE"); // may be NULL
img.load_pfm(path);
// after
const char* path = getenv("HDR_FILE");
if (path) {
img.load_pfm(path);
} else {
std::fprintf(stderr, "HDR_FILE not set\n");
} Defensive patterns
Strategy: type-guard
Validate before calling
if (path == nullptr || path[0] == '\0') {
throw std::invalid_argument("PFM path must be set before load_pfm");
} Type guard
bool hasSource(std::FILE* f, const char* name) { return f != nullptr || name != nullptr; } Try / catch
try {
img.load_pfm(path);
} catch (cimg_library::CImgArgumentException& e) {
std::cerr << "No PFM source given: " << e.what() << "\n";
} Prevention
- Null-check env/config lookups before using the value as a filename
- Prefer std::string over raw char* for paths
- Always open the FILE* before using FILE*-overloads
- Fail fast with a clear message when a required path is unset
When it happens
Trigger: Calling load_pfm(nullptr) or load_pfm(nullptr, nullptr); passing a filename variable that is NULL (e.g. from getenv or an uninitialized char*); programmatically constructing a CImg load chain where the source path was never set.
Common situations: Configuration lookups returning NULL for the image path; forgetting to default-initialize a filename buffer; calling the FILE*-overload without opening the file first.
Related errors
- load_jpeg(): Specified filename is (null).
- load_jxl(): Specified filename is (null).
- load_magick(): Specified filename is (null).
- load_pfm(): PFM header not found in file '%s'.
- load_pfm(): WIDTH and HEIGHT fields are undefined in file '%
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/da14eef10d99b45d.
Report an issue: GitHub.