Yalantis/uCrop · error · CImgArgumentException

save_dlm(): Specified filename is (null).

Error message

save_dlm(): Specified filename is (null).

What it means

save_dlm() writes the image as a Matrix Market-style delimited (DLM) text file; _save_dlm() throws CImgArgumentException when both the FILE* and filename are null, i.e., no output destination was given.

Source

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

      return *this;
    }

    //! Save image as a DLM file.
    /**
       \param filename Filename, as a C-string.
    **/
    const CImg<T>& save_dlm(const char *const filename) const {
      return _save_dlm(0,filename);
    }

    //! Save image as a DLM file \overloading.
    const CImg<T>& save_dlm(std::FILE *const file) const {
      return _save_dlm(file,0);
    }

    const CImg<T>& _save_dlm(std::FILE *const file, const char *const filename) const {
      if (!file && !filename)
        throw CImgArgumentException(_cimg_instance
                                    "save_dlm(): Specified filename is (null).",
                                    cimg_instance);
      if (is_empty()) { cimg::fempty(file,filename); return *this; }
      if (_depth>1)
        cimg::warn(_cimg_instance
                   "save_dlm(): Instance is volumetric, values along Z will be unrolled in file '%s'.",
                   cimg_instance,
                   filename?filename:"(FILE*)");
      if (_spectrum>1)
        cimg::warn(_cimg_instance
                   "save_dlm(): Instance is multispectral, values along C will be unrolled in file '%s'.",
                   cimg_instance,
                   filename?filename:"(FILE*)");

      std::FILE *const nfile = file?file:cimg::fopen(filename,"w");
      const T* ptrs = _data;
      cimg_forYZC(*this,y,z,c) {
        cimg_forX(*this,x) std::fprintf(nfile,"%.17g%s",(double)*(ptrs++),(x==width() - 1)?"":",");

View on GitHub (pinned to f788b534b4)

Solutions

  1. Pass a valid filename (e.g., img.save_dlm("data.txt")).
  2. Ensure the FILE* from fopen is non-NULL before the FILE* overload.
  3. Null-check file and filename at the call site.
  4. Log errno from fopen to fix the underlying open failure.

Example fix

// before
FILE* f = fopen(path, "w"); img.save_dlm(f);
// after
FILE* f = fopen(path, "w");
if (!f) { perror("fopen"); return; }
img.save_dlm(f); fclose(f);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!file && (!filename || !*filename)) { /* abort or use default path */ }

Type guard

bool hasDestination(std::FILE* f, const char* n){ return f!=nullptr || (n!=nullptr && *n!='\0'); }

Try / catch

try { img.save_dlm(f); } catch (CImgArgumentException& e) { fprintf(stderr,"DLM save failed: %s\n", e.what()); }

Prevention

When it happens

Trigger: Calling img.save_dlm((std::FILE*)NULL) or img.save_dlm((const char*)NULL); passing a NULL FILE* from a failed fopen to the FILE* overload.

Common situations: Exporting numeric data to MATLAB-compatible text where the output path came from an unset config value; fopen failures passed through.

Related errors


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