Yalantis/uCrop · error · CImgDisplayException

CImgDisplay::screenshot(): Failed to open X11 display.

Error message

CImgDisplay::screenshot(): Failed to open X11 display.

What it means

Thrown by the static CImgDisplay::screenshot() when no X server is reachable: the shared X11_attr display is null and the fallback XOpenDisplay(0) call also fails, so screen pixels cannot be captured.

Solutions

  1. Set DISPLAY to a valid X server (e.g. :0) and confirm the server is running
  2. Use a virtual X server such as Xvfb for headless screenshot capture
  3. Grant X server access if connecting remotely (xhost + or proper X authorization cookies)
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at ucrop/src/main/jni/CImg.h:11271 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

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

            delete[] ndata;
          }
        }
        }
      }
      X11_attr.unlock();
      return *this;
    }

    template<typename T>
    static void screenshot(const int x0, const int y0, const int x1, const int y1, CImg<T>& img) {
      img.assign();
      cimg::X11_attr &X11_attr = cimg::X11_attr::ref();
      Display *dpy = X11_attr.display;
      X11_attr.lock();
      if (!dpy) {
        dpy = XOpenDisplay(0);
        if (!dpy)
          throw CImgDisplayException("CImgDisplay::screenshot(): Failed to open X11 display.");
      }
      Window root = DefaultRootWindow(dpy);
      XWindowAttributes gwa;
      XGetWindowAttributes(dpy,root,&gwa);
      const int width = gwa.width, height = gwa.height;
      int _x0 = x0, _y0 = y0, _x1 = x1, _y1 = y1;
      if (_x0>_x1) cimg::swap(_x0,_x1);
      if (_y0>_y1) cimg::swap(_y0,_y1);

      XImage *image = 0;
      if (_x1>=0 && _x0<width && _y1>=0 && _y0<height) {
        _x0 = std::max(_x0,0);
        _y0 = std::max(_y0,0);
        _x1 = std::min(_x1,width - 1);
        _y1 = std::min(_y1,height - 1);
        image = XGetImage(dpy,root,_x0,_y0,_x1 - _x0 + 1,_y1 - _y0 + 1,AllPlanes,ZPixmap);

        if (image) {

View on GitHub (pinned to f788b534b4)