Yalantis/uCrop · error · CImgDisplayException

CImgDisplay(): No display available.

Error message

CImgDisplay(): No display available.

What it means

When CImg is compiled with cimg_display==0 (no display support), every CImgDisplay constructor/operation routes through _no_display_exception(), which throws CImgDisplayException. This build simply has no windowing backend (X11/GDI/SDL) linked in, so no display object can ever exist.

Source

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

      _window_x(cimg::type<int>::min()),_window_y(cimg::type<int>::min()),
      _mouse_x(-1),_mouse_y(-1),_wheel(0),
      _is_closed(true),_is_resized(false),_is_moved(false),_is_event(false) {
      assign(disp);
    }

    //! Take a screenshot.
    /**
       \param[out] img Output screenshot. Can be empty on input
    **/
    template<typename T>
    static void screenshot(CImg<T>& img) {
      return screenshot(0,0,cimg::type<int>::max(),cimg::type<int>::max(),img);
    }

#if cimg_display==0

    static void _no_display_exception() {
      throw CImgDisplayException("CImgDisplay(): No display available.");
    }

    //! Destructor - Empty constructor \inplace.
    /**
       \note Replace the current instance by an empty display.
    **/
    CImgDisplay& assign() {
      return flush();
    }

    //! Construct a display with specified dimensions \inplace.
    /**
    **/
    CImgDisplay& assign(const unsigned int width, const unsigned int height,
                        const char *const title=0, const unsigned int normalization=3,
                        const bool is_fullscreen=false, const bool is_closed=false) {
      cimg::unused(width,height,title,normalization,is_fullscreen,is_closed);
      _no_display_exception();

View on GitHub (pinned to f788b534b4)

Solutions

  1. Remove CImgDisplay usage from headless builds — render to files or offscreen buffers instead
  2. Rebuild with display support (cimg_display=1 and X11 dev headers installed) if a GUI is truly needed
  3. Guard display code with #if cimg_display!=0 preprocessor checks

Example fix

// before
CImgDisplay disp(img, "preview"); // cimg_display==0
// after
#if cimg_display!=0
CImgDisplay disp(img, "preview");
#else
img.save("preview.png"); // headless fallback
#endif
Defensive patterns

Strategy: fallback

Validate before calling

#if cimg_display==0
  // compile-time: display code is disabled — do not instantiate CImgDisplay
#endif

Type guard

bool displaySupported() { return cimg_display != 0; }

Try / catch

try { cimg::CImgDisplay d(img, "preview"); } catch (const cimg_library::CImgDisplayException &e) { img.save("preview.png"); // headless fallback
}

Prevention

When it happens

Trigger: Constructing CImgDisplay or calling CImgDisplay::wait/assign/etc. in a binary built with cimg_display=0, or where none of the supported display libraries were detected at compile time.

Common situations: Building the Android NDK/JNI library (headless, no display headers) but reusing GUI code; cross-compiling on a machine without X11 headers so CImg silently disables display support.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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