Yalantis/uCrop · error · CImgArgumentException

load_gif_external(): Specified filename is (null) or does no

Error message

load_gif_external(): Specified filename is (null) or does not exist.

What it means

CImgList::load_gif_external() reads GIFs via ImageMagick/GraphicsMagick's external tools. Before invoking anything, it validates the filename and throws this CImgArgumentException if the pointer is null or the path is not an existing regular file. It is a pure input-validation failure raised before any conversion is attempted.

Source

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

        throw CImgIOException(_cimglist_instance
                              "load_ffmpeg_external(): Failed to open file '%s' with external command 'ffmpeg'.",
                              cimglist_instance,
                              filename);
      return *this;
    }

    //! Load an image from a video file using the external tool 'ffmpeg' \newinstance.
    static CImgList<T> get_load_ffmpeg_external(const char *const filename) {
      return CImgList<T>().load_ffmpeg_external(filename);
    }

    //! Load gif file, using ImageMagick or GraphicsMagick's external tools.
    /**
      \param filename Filename to read data from.
    **/
    CImgList<T>& load_gif_external(const char *const filename) {
      if (!filename || !cimg::is_file(filename))
        throw CImgArgumentException(_cimglist_instance
                                    "load_gif_external(): Specified filename is (null) or does not exist.",
                                    cimglist_instance);
      if (!_load_gif_external(filename,false))
        if (!_load_gif_external(filename,true))
          try { assign(CImg<T>().load_other(filename)); } catch (CImgException&) { assign(); }
      if (is_empty())
        throw CImgIOException(_cimglist_instance
                              "load_gif_external(): Failed to open file '%s'.",
                              cimglist_instance,filename);
      return *this;
    }

    CImgList<T>& _load_gif_external(const char *const filename, const bool use_graphicsmagick=false) {
      CImg<charT> command(1024), filename_tmp(256), filename_tmp2(256);
      do {
        cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s",
                      cimg::temporary_path(),cimg_file_separator,cimg::filenamerand());
        if (use_graphicsmagick) cimg_snprintf(filename_tmp2,filename_tmp2._width,"%s.png.0",filename_tmp._data);

View on GitHub (pinned to f788b534b4)

Solutions

  1. Verify the path exists and is a regular file (std::filesystem::is_regular_file) before calling.
  2. Use absolute paths and confirm the working directory for relative ones.
  3. Extract Android content:// or resource URIs to a cache file first, then pass that path.

Example fix

// before
list.load_gif_external("assets/anim.gif"); // never extracted to disk

// after
// extract APK asset to cache first
std::string path = extractAssetToCache("anim.gif");
if (std::filesystem::is_regular_file(path))
  list.load_gif_external(path.c_str());
Defensive patterns

Strategy: validation

Validate before calling

bool usableGif(const char* p) {
  return p != nullptr && std::filesystem::is_regular_file(p);
}
if (!usableGif(path)) { /* resolve path first */ }

Type guard

bool isExistingFile(const char* p) {
  return p != nullptr && std::filesystem::exists(p) &&
         std::filesystem::is_regular_file(p);
}

Try / catch

try {
  list.load_gif_external(path);
} catch (CImgArgumentException&) {
  // invalid/missing path: report to caller
}

Prevention

When it happens

Trigger: Calling load_gif_external(nullptr), or with a path that does not exist, is a directory, or is otherwise not a regular file.

Common situations: Wrong relative path / working directory; animated GIF deleted or renamed before load; native code on Android given a resource ID or URI instead of an extracted file path.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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