Yalantis/uCrop · error · CImgIOException

cimg::load_network(): Loading files from network is disabled

Error message

cimg::load_network(): Loading files from network is disabled.

What it means

cimg::load_network() refuses to run when cimg::network_mode() returns false, throwing this CImgIOException. Network loading is a compile/runtime-configurable capability of CImg; when disabled (built with cimg_use_no_network or runtime-disabled), any attempt to download a file is rejected up front rather than silently failing.

Source

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

    /**
       \param url URL of the filename, as a C-string.
       \param[out] filename_local C-string containing the path to a local copy of \c filename.
       \param timeout Maximum time (in seconds) authorized for downloading the file from the URL.
       \param try_fallback When using libcurl, tells using system calls as fallbacks in case of libcurl failure.
       \param referer Referer used, as a C-string.
       \param user_agent User agent used, as a C-string.
       \return Value of \c filename_local.
       \note Use the \c libcurl library, or the external binaries \c wget or \c curl to perform the download.
    **/
    inline char *load_network(const char *const url, char *const filename_local,
                              const unsigned int timeout, const bool try_fallback,
                              const char *const referer, const char *const user_agent) {
      if (!url)
        throw CImgArgumentException("cimg::load_network(): Specified URL is (null).");
      if (!filename_local)
        throw CImgArgumentException("cimg::load_network(): Specified destination string is (null).");
      if (!network_mode())
        throw CImgIOException("cimg::load_network(): Loading files from network is disabled.");

      const char *const __ext = cimg::split_filename(url), *const _ext = (*__ext && __ext>url)?__ext - 1:__ext;
      CImg<char> ext = CImg<char>::string(_ext);
      *filename_local = 0;
      if (ext._width>16 || !cimg::strncasecmp(ext,"cgi",3)) *ext = 0;
      else cimg::strwindows_reserved(ext);
      do {
        cimg_snprintf(filename_local,256,"%s%c%s%s",
                      cimg::temporary_path(),cimg_file_separator,cimg::filenamerand(),ext._data);
      } while (cimg::path_exists(filename_local));

#ifdef cimg_use_curl
      const unsigned int omode = cimg::exception_mode();
      cimg::exception_mode(0);
      try {
        CURL *curl = 0;
        CURLcode res;
        curl = curl_easy_init();

View on GitHub (pinned to f788b534b4)

Solutions

  1. Enable network support in the CImg build configuration (link libcurl and remove cimg_use_no_network / define network mode on) if downloads are needed.
  2. If network loading is intentionally disabled, download the file yourself (via your HTTP client) to a local path and load that local file with CImg instead.
  3. Avoid http(s):// URLs in load paths when the build has no network support.
  4. Catch CImgIOException around load_network and fall back to bundled/local assets.

Example fix

// before
img.load_network(remoteUrl, localPath); // throws: network disabled
// after
std::string local = downloadWithAppHttpClient(remoteUrl); // app's own HTTP layer
img.load(local.c_str());
Defensive patterns

Strategy: fallback

Validate before calling

if (!cimg::network_mode()) {
  std::string local = downloadWithAppHttpClient(remoteUrl);
  img.load(local.c_str());
} else {
  img.load_network(remoteUrl, local, 30, true, 0, 0);
}

Try / catch

try { img.load_network(url, local, 30, true, 0, 0); } catch (const CImgIOException &e) { /* network disabled: use bundled asset */ img.load("assets/default.png"); }

Prevention

When it happens

Trigger: Calling load_network() (or CImg<T>::load_network / load on a http:// URL) while the CImg library was compiled with network support disabled, or network_mode() was turned off at runtime.

Common situations: Bundling CImg in an Android/iOS NDK build (like uCrop) without enabling libcurl-based network support; desktop builds with cimg_display/cimg network flags off; apps that deliberately disable network file loading for sandboxing.

Related errors


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