Yalantis/uCrop · error · CImgIOException

load_dlm(): Invalid DLM file '%s'.

Error message

load_dlm(): Invalid DLM file '%s'.

What it means

load_dlm() failed to parse at least one row and one column of numeric values from the delimiter-separated file, so dx or dy ended up 0 and it throws CImgIOException. The file opened but its content is not valid DLM numeric data.

Source

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

      CImg<charT> delimiter(256), tmp(256); *delimiter = *tmp = 0;
      unsigned int cdx = 0, dx = 0, dy = 0;
      int err = 0;
      double val;
      assign(256,256,1,1,(T)0);
      while ((err = std::fscanf(nfile,"%lf%255[^0-9eEinfa.+-]",&val,delimiter._data))>0) {
        if (err>0) (*this)(cdx++,dy) = (T)val;
        if (cdx>=_width) resize(3*_width/2,_height,1,1,0);
        char c = 0;
        if (!cimg_sscanf(delimiter,"%255[^\n]%c",tmp._data,&c) || c=='\n') {
          dx = std::max(cdx,dx);
          if (++dy>=_height) resize(_width,3*_height/2,1,1,0);
          cdx = 0;
        }
      }
      if (cdx && err==1) { dx = cdx; ++dy; }
      if (!dx || !dy) {
        if (!file) cimg::fclose(nfile);
        throw CImgIOException(_cimg_instance
                              "load_dlm(): Invalid DLM file '%s'.",
                              cimg_instance,
                              filename?filename:"(FILE*)");
      }
      resize(dx,dy,1,1,0);
      if (!file) cimg::fclose(nfile);
      return *this;
    }

    //! Load image from a BMP file.
    /**
       \param filename Filename, as a C-string.
    **/
    CImg<T>& load_bmp(const char *const filename) {
      return _load_bmp(0,filename);
    }

    //! Load image from a BMP file \newinstance.

View on GitHub (pinned to f788b534b4)

Solutions

  1. Check the file is non-empty and contains rows of parseable numbers.
  2. Pass the correct delimiter character/string matching the file (e.g. "," vs ";" vs "\t").
  3. Strip header rows / BOM before loading, or pre-clean the file.
  4. Open the file with a text editor to confirm format matches DLM expectations.

Example fix

// before
img.load_dlm(path, 0); // default delim, file is ';'-separated
// after
img.load_dlm(path, ";");
Defensive patterns

Strategy: validation

Validate before calling

bool looksLikeNumericDlm(const char* p, const char* delim){ std::ifstream in(p); std::string line; if(!std::getline(in,line)||line.empty()) return false; return line.find_first_of("0123456789.eE+-")!=std::string::npos; }

Try / catch

try { img.load_dlm(path, delim); } catch (cimg_library::CImgIOException& e) { /* unparseable or empty DLM data */ }

Prevention

When it happens

Trigger: Loading a CSV/DLM file whose rows parse to zero columns (wrong delimiter character passed) or which is empty/contains only non-numeric text so no rows are counted.

Common situations: Passing the wrong delimiter string (file is ';'-separated but load called with default), loading an Excel-exported file with BOM/headers, or passing an empty file.

Related errors


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