Yalantis/uCrop · error · CImgArgumentException

load_rgb(): Specified filename is (null).

Error message

load_rgb(): Specified filename is (null).

What it means

CImg<T>::_load_rgb() reads raw interleaved RGB bytes from a FILE* or a named file. Like the other raw loaders it requires one of the two sources; if both the FILE* and filename are null it throws CImgArgumentException because there is no input stream to read.

Source

Thrown at ucrop/src/main/jni/CImg.h:57869

    //! Load image from a RGB file \newinstance.
    static CImg<T> get_load_rgb(const char *const filename, const unsigned int dimw, const unsigned int dimh=1) {
      return CImg<T>().load_rgb(filename,dimw,dimh);
    }

    //! Load image from a RGB file \overloading.
    CImg<T>& load_rgb(std::FILE *const file, const unsigned int dimw, const unsigned int dimh=1) {
      return _load_rgb(file,0,dimw,dimh);
    }

    //! Load image from a RGB file \newinstance.
    static CImg<T> get_load_rgb(std::FILE *const file, const unsigned int dimw, const unsigned int dimh=1) {
      return CImg<T>().load_rgb(file,dimw,dimh);
    }

    CImg<T>& _load_rgb(std::FILE *const file, const char *const filename,
                       const unsigned int dimw, const unsigned int dimh) {
      if (!file && !filename)
        throw CImgArgumentException(_cimg_instance
                                    "load_rgb(): Specified filename is (null).",
                                    cimg_instance);

      if (!dimw || !dimh) return assign();
      const longT cimg_iobuffer = (longT)24*1024*1024;
      std::FILE *const nfile = file?file:cimg::fopen(filename,"rb");
      CImg<ucharT> raw;
      assign(dimw,dimh,1,3);
      T
        *ptr_r = data(0,0,0,0),
        *ptr_g = data(0,0,0,1),
        *ptr_b = data(0,0,0,2);
      for (longT to_read = (longT)size(); to_read>0; ) {
        raw.assign(std::min(to_read,cimg_iobuffer));
        cimg::fread(raw._data,raw._width,nfile);
        to_read-=raw._width;
        const unsigned char *ptrs = raw._data;
        for (ulongT off = raw._width/3UL; off; --off) {

View on GitHub (pinned to f788b534b4)

Solutions

  1. Pass a valid filename: img.load_rgb("frame.rgb", w, h).
  2. Open the file first and pass the FILE* handle to load_rgb.
  3. Null-check/guard the path before the call and provide a default or clear error.
  4. Trace why the configured path resolved to NULL (missing config key, failed env lookup).
  5. Catch CImgArgumentException where paths are user-supplied and optional.

Example fix

// before
FILE* f = NULL;
img.load_rgb(f, dimw, dimh); // never opened
// after
FILE* f = std::fopen("frame.rgb", "rb");
if (f) {
  img.load_rgb(f, dimw, dimh);
  std::fclose(f);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (path == nullptr || path[0] == '\0') {
  throw std::invalid_argument("RGB path must be set before load_rgb");
}

Type guard

bool hasSource(std::FILE* f, const char* name) { return f != nullptr || name != nullptr; }

Try / catch

try {
  img.load_rgb(path, dimw, dimh);
} catch (cimg_library::CImgArgumentException& e) {
  std::cerr << "No RGB source given: " << e.what() << "\n";
}

Prevention

When it happens

Trigger: Calling load_rgb(nullptr, w, h) or _load_rgb with a NULL filename; a path variable from a failed lookup (getenv/config) that is NULL; invoking the FILE*-overload before opening the file.

Common situations: Raw framebuffer/video-frame loaders where the file path comes from configuration that was never set; uninitialized char* filename; pipeline stages passing through empty paths.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/826efd98c61729d5. Report an issue: GitHub.