Yalantis/uCrop · error · CImgArgumentException
load_exr(): Specified filename is (null).
Error message
load_exr(): Specified filename is (null).
What it means
load_exr() loads OpenEXR images. It throws CImgArgumentException immediately if the filename pointer is null, before touching any EXR backend (OpenEXR or tinyexr). Like the other load_* null guards, it signals an API call with no input source.
Source
Thrown at ucrop/src/main/jni/CImg.h:58746
_cimg_load_inr_case(1,1,64,double);
if (!loaded) {
if (!file) cimg::fclose(nfile);
throw CImgIOException(_cimg_instance
"load_inr(): Unknown pixel type defined in file '%s'.",
cimg_instance,
filename?filename:"(FILE*)");
}
if (!file) cimg::fclose(nfile);
return *this;
}
//! Load image from a EXR file.
/**
\param filename Filename, as a C-string.
**/
CImg<T>& load_exr(const char *const filename) {
if (!filename)
throw CImgArgumentException(_cimg_instance
"load_exr(): Specified filename is (null).",
cimg_instance);
#if defined(cimg_use_openexr)
Imf::RgbaInputFile file(filename);
Imath::Box2i dw = file.dataWindow();
const int
inwidth = dw.max.x - dw.min.x + 1,
inheight = dw.max.y - dw.min.y + 1;
Imf::Array2D<Imf::Rgba> pixels;
pixels.resizeErase(inheight,inwidth);
file.setFrameBuffer(&pixels[0][0] - dw.min.x - dw.min.y*inwidth, 1, inwidth);
file.readPixels(dw.min.y, dw.max.y);
assign(inwidth,inheight,1,4);
T *ptr_r = data(0,0,0,0), *ptr_g = data(0,0,0,1), *ptr_b = data(0,0,0,2), *ptr_a = data(0,0,0,3);
cimg_forXY(*this,x,y) {
*(ptr_r++) = (T)pixels[y][x].r;
*(ptr_g++) = (T)pixels[y][x].g;
*(ptr_b++) = (T)pixels[y][x].b;View on GitHub (pinned to f788b534b4)
Solutions
- Null/empty-check the path before the call
- Fix the source of the path (env var, config, API) so a real filename is produced
- Use a non-EXR loader if the file is actually another format and the wrong loader was selected
Example fix
// before
img.load_exr(config.get("exr_path")); // may be NULL
// after
const char *p = config.get("exr_path");
if (!p) throw std::runtime_error("exr_path not configured");
img.load_exr(p); Defensive patterns
Strategy: validation
Validate before calling
if (!filename || !*filename) { throw std::invalid_argument("filename required for load_exr"); } Type guard
bool is_valid_path(const char *p) { return p != nullptr && *p != '\0'; } Try / catch
try { img.load_exr(path); } catch (const cimg_library::CImgArgumentException &e) { log(e.what()); } Prevention
- Validate all paths at the boundary where they enter your code
- Fail fast on missing config/env values instead of forwarding null
- Use typed path wrappers (std::filesystem::path) and check !empty() before c_str()
When it happens
Trigger: Calling img.load_exr(NULL) directly, or passing a lookup result (getenv, map find, config read) that returned null as the filename.
Common situations: Missing env var or config entry for the EXR path; a path-building function returned NULL on failure; FFI/bindings converting an empty optional to null.
Related errors
- load_jpeg(): Specified filename is (null).
- load_jxl(): Specified filename is (null).
- load_magick(): Specified filename is (null).
- load_pfm(): Specified filename is (null).
- load_rgb(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/2a1c749e4c0fa209.
Report an issue: GitHub.