Yalantis/uCrop · error · CImgArgumentException
load_raw(): Specified filename is (null).
Error message
load_raw(): Specified filename is (null).
What it means
CImg's raw loader _load_raw() reads uncompressed pixel data of given dimensions from a FILE* or a named file. It throws CImgArgumentException when both file and filename are null, since there is nothing to read from. This guard runs before the directory check and any I/O.
Solutions
- Check filename non-null (and non-empty) before calling load_raw
- Fix the upstream producer of the path (env var, config, previous pipeline step)
- If a FILE* is intended, ensure fopen succeeded before passing it
- Also verify the path is a file, not a directory (the next check after this one)
Example fix
// before
img.load_raw(path, dims...);
// after
if (!path || !*path) throw std::invalid_argument("raw file path required");
struct stat st;
if (stat(path, &st) != 0 || S_ISDIR(st.st_mode)) throw std::invalid_argument("not a file");
img.load_raw(path, dims...); Defensive patterns
Strategy: validation
Validate before calling
if (!filename || !*filename) throw std::invalid_argument("raw file path required");
struct stat st;
if (stat(filename,&st)!=0) throw std::runtime_error("raw file does not exist");
if (S_ISDIR(st.st_mode)) throw std::invalid_argument("path is a directory"); Type guard
bool is_loadable_file(const char *p) {
if (!p || !*p) return false;
struct stat st; return stat(p,&st)==0 && S_ISREG(st.st_mode);
} Try / catch
try { img.load_raw(path, dims...); } catch (const cimg_library::CImgArgumentException &e) { /* null path or directory */ log(e.what()); } Prevention
- Validate path is non-null, non-empty, and a regular file before load_raw
- Check raw-dimensions math against actual file size to avoid downstream read errors
- Fail loudly in pipeline steps that produce paths so null never propagates to loaders
When it happens
Trigger: img.load_raw(NULL,...) with no FILE*; a null path from an unset env var or failed lookup; generic wrapper code forwarding null through to the loader.
Common situations: Missing config/env values for raw data paths; wrappers around load_raw that don't validate arguments; pipelines where an earlier step failed silently and produced a null path.
Related errors
- load_exr(): Specified filename is (null).
- load_inr(): Specified filename is (null).
- load_jpeg(): Specified filename is (null).
- load_jxl(): Specified filename is (null).
- load_magick(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/3d8b278a83fcc6ba.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:59089
return _load_raw(file,0,size_x,size_y,size_z,size_c,is_multiplexed,invert_endianness,offset);
}
//! Load image from a raw binary file \newinstance.
static CImg<T> get_load_raw(std::FILE *const file,
const unsigned int size_x=0, const unsigned int size_y=1,
const unsigned int size_z=1, const unsigned int size_c=1,
const bool is_multiplexed=false, const bool invert_endianness=false,
const ulongT offset=0) {
return CImg<T>().load_raw(file,size_x,size_y,size_z,size_c,is_multiplexed,invert_endianness,offset);
}
CImg<T>& _load_raw(std::FILE *const file, const char *const filename,
const unsigned int size_x, const unsigned int size_y,
const unsigned int size_z, const unsigned int size_c,
const bool is_multiplexed, const bool invert_endianness,
const ulongT offset) {
if (!file && !filename)
throw CImgArgumentException(_cimg_instance
"load_raw(): Specified filename is (null).",
cimg_instance);
if (cimg::is_directory(filename))
throw CImgArgumentException(_cimg_instance
"load_raw(): Specified filename '%s' is a directory.",
cimg_instance,filename);
const bool is_bool = pixel_type()==cimg::type<bool>::string();
ulongT siz = (ulongT)size_x*size_y*size_z*size_c;
unsigned int
_size_x = size_x,
_size_y = size_y,
_size_z = size_z,
_size_c = size_c;
std::FILE *const nfile = file?file:cimg::fopen(filename,"rb");
if (!siz) { // Retrieve file size
const longT fpos = cimg::ftell(nfile);
if (fpos<0) throw CImgArgumentException(_cimg_instance
"load_raw(): Cannot determine size of input file '%s'.",View on GitHub (pinned to f788b534b4)