Yalantis/uCrop · error · CImgArgumentException

load_minc2(): Specified filename is (null).

Error message

load_minc2(): Specified filename is (null).

What it means

CImg<T>::load_minc2() throws a CImgArgumentException when the filename pointer is null, mirroring the other loaders. Note that without cimg_use_minc2 defined, the function simply delegates to load_other(); the null check happens first regardless of build configuration.

Solutions

  1. Pass a valid non-null filename string.
  2. Check env/config lookups for NULL before calling and default appropriately.
  3. If MINC2 support is needed, build with cimg_use_minc2; otherwise ensure the file is a format load_other() handles.

Example fix

// before
img.load_minc2(cfg.mincPath); // may be NULL
// after
if (cfg.mincPath) img.load_minc2(cfg.mincPath);
else throw std::runtime_error("mincPath missing");
Defensive patterns

Strategy: validation

Validate before calling

if (!mincPath || !*mincPath) throw std::invalid_argument("load_minc2 requires a non-null filename");
img.load_minc2(mincPath);

Type guard

bool hasMincPath(const char *p) { return p != nullptr && *p != '\0'; }

Try / catch

try { img.load_minc2(path); }
catch (CImgArgumentException &e) { log("null path passed to load_minc2"); }

Prevention

When it happens

Trigger: img.load_minc2(NULL), or passing a null path obtained from an unset environment variable or failed lookup.

Common situations: Optional MINC file paths from config/env defaults that resolve to null, or native code receiving a null string from a managed caller.

Related errors


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

Appendix: source

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

              if (sampleformat==SAMPLEFORMAT_UINT) _load_tiff_separate<uint64T>(tif,samplesperpixel,nx,ny);
              else if (sampleformat==SAMPLEFORMAT_INT) _load_tiff_separate<int64T>(tif,samplesperpixel,nx,ny);
              else _load_tiff_separate<double>(tif,samplesperpixel,nx,ny);
              break;
            }
        }
      }
      return *this;
    }
#endif

    //! Load image from a MINC2 file.
    /**
        \param filename Filename, as a C-string.
    **/
    // (Original code by Haz-Edine Assemlal).
    CImg<T>& load_minc2(const char *const filename) {
      if (!filename)
        throw CImgArgumentException(_cimg_instance
                                    "load_minc2(): Specified filename is (null).",
                                    cimg_instance);
#ifndef cimg_use_minc2
      return load_other(filename);
#else
      minc::minc_1_reader rdr;
      rdr.open(filename);
      assign(rdr.ndim(1)?rdr.ndim(1):1,
             rdr.ndim(2)?rdr.ndim(2):1,
             rdr.ndim(3)?rdr.ndim(3):1,
             rdr.ndim(4)?rdr.ndim(4):1);
      if (pixel_type()==cimg::type<unsigned char>::string())
        rdr.setup_read_byte();
      else if (pixel_type()==cimg::type<int>::string())
        rdr.setup_read_int();
      else if (pixel_type()==cimg::type<double>::string())
        rdr.setup_read_double();
      else

View on GitHub (pinned to f788b534b4)