Yalantis/uCrop · error · CImgArgumentException

load_rgba(): Specified filename is (null).

Error message

load_rgba(): Specified filename is (null).

What it means

CImg<T>::_load_rgba() reads raw interleaved RGBA bytes and, like load_rgb, requires either an open FILE* or a non-null filename. When both are null it throws CImgArgumentException before any I/O, since there is no source to read from.

Source

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

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

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

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

    CImg<T>& _load_rgba(std::FILE *const file, const char *const filename,
                        const unsigned int dimw, const unsigned int dimh) {
      if (!file && !filename)
        throw CImgArgumentException(_cimg_instance
                                    "load_rgba(): 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,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);
      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;

View on GitHub (pinned to f788b534b4)

Solutions

  1. Provide a valid filename: img.load_rgba("sprite.rgba", w, h).
  2. Open the file and pass the FILE*: fopen + load_rgba(f, w, h) + fclose.
  3. Guard against a null path before calling and log a meaningful error.
  4. Verify the configuration actually provides the RGBA asset path.
  5. Catch CImgArgumentException when the asset is optional and fall back to a default texture.

Example fix

// before
const char* tex = cfg.get("texture"); // NULL when key missing
img.load_rgba(tex, 256, 256);
// after
const char* tex = cfg.get("texture");
if (tex) img.load_rgba(tex, 256, 256);
else img.load_rgba("default.rgba", 256, 256);
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

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

Try / catch

try {
  img.load_rgba(path, dimw, dimh);
} catch (cimg_library::CImgArgumentException& e) {
  std::cerr << "No RGBA source given: " << e.what() << "\n";
  img.assign(); // fall back to empty/default image
}

Prevention

When it happens

Trigger: Calling load_rgba(nullptr, w, h); passing a NULL filename from a failed config/env lookup; using the FILE*-overload with an unopened or already-closed FILE* set to NULL.

Common situations: Texture-loading pipelines where the asset path is optional and unset; uninitialized filename pointers; refactor changed the call from filename-overload to FILE*-overload without opening the file.

Related errors


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