Yalantis/uCrop · error · CImgArgumentException

save_other(): Specified filename is (null).

Error message

save_other(): Specified filename is (null).

What it means

CImg::save_other() is the catch-all saver that tries a sequence of external tools (ImageMagick, GraphicsMagick, medcon) for formats CImg does not support natively. A NULL filename is rejected up front with CImgArgumentException before any tool is attempted.

Solutions

  1. Check the filename for NULL before calling save_other().
  2. Fix the upstream path resolution that returned NULL.
  3. Default to a sensible output filename when none is provided.
  4. Route through std::string and validate non-empty before .c_str().

Example fix

// before
void saveImg(const CImg<float>& img, const char* p) { img.save_other(p); }
// after
void saveImg(const CImg<float>& img, const char* p) {
  if (!p || !*p) p = "output.png";
  img.save_other(p);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (!filename || !*filename) { filename = "output.png"; }

Type guard

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

Try / catch

try {
  img.save_other(filename);
} catch (CImgArgumentException& e) {
  std::fprintf(stderr, "invalid filename: %s", e.what());
}

Prevention

When it happens

Trigger: Calling save_other(nullptr) or passing an uninitialized/NULL char* filename.

Common situations: Generic save wrappers that forward a user-supplied path which failed to resolve; config or CLI parsing that left the output path NULL.

Related errors


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

Appendix: source

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

      return *this;
    }

    // Save image for non natively supported formats.
    /**
       \param filename Filename, as a C-string.
       \param quality Image quality (expressed in percent), when the file format supports it.
       \note
       - The filename extension tells about the desired file format.
       - This method tries to save the instance image as a file, using external tools from
       <a href="http://www.imagemagick.org">ImageMagick</a> or
       <a href="http://www.graphicsmagick.org">GraphicsMagick</a>.
         At least one of these tool must be installed for the method to succeed.
       - It is recommended to use the generic method save(const char*, int) const instead,
         as it can handle some file formats natively.
    **/
    const CImg<T>& save_other(const char *const filename, const unsigned int quality=100) const {
      if (!filename)
        throw CImgArgumentException(_cimg_instance
                                    "save_other(): Specified filename is (null).",
                                    cimg_instance);
      if (is_empty()) { cimg::fempty(0,filename); return *this; }
      if (_depth>1)
        cimg::warn(_cimg_instance
                   "save_other(): File '%s', saving a volumetric image with an external call to "
                   "ImageMagick or GraphicsMagick only writes the first image slice.",
                   cimg_instance,filename);

      const unsigned int omode = cimg::exception_mode();
      bool is_saved = true;
      cimg::exception_mode(0);
      try { save_magick(filename); }
      catch (CImgException&) {
        try { save_imagemagick_external(filename,quality); }
        catch (CImgException&) {
          try { save_graphicsmagick_external(filename,quality); }
          catch (CImgException&) {

View on GitHub (pinned to f788b534b4)