{"record":{"id":"f803b1d1392405f4","repo":"Yalantis/uCrop","slug":"cimgdisplay-screenshot-failed-to-open-x11-disp","errorCode":null,"errorMessage":"CImgDisplay::screenshot(): Failed to open X11 display.","messagePattern":"CImgDisplay::screenshot\\(\\): Failed to open X11 display\\.","errorType":"exception","errorClass":"CImgDisplayException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":11271,"sourceCode":"            delete[] ndata;\n          }\n        }\n        }\n      }\n      X11_attr.unlock();\n      return *this;\n    }\n\n    template<typename T>\n    static void screenshot(const int x0, const int y0, const int x1, const int y1, CImg<T>& img) {\n      img.assign();\n      cimg::X11_attr &X11_attr = cimg::X11_attr::ref();\n      Display *dpy = X11_attr.display;\n      X11_attr.lock();\n      if (!dpy) {\n        dpy = XOpenDisplay(0);\n        if (!dpy)\n          throw CImgDisplayException(\"CImgDisplay::screenshot(): Failed to open X11 display.\");\n      }\n      Window root = DefaultRootWindow(dpy);\n      XWindowAttributes gwa;\n      XGetWindowAttributes(dpy,root,&gwa);\n      const int width = gwa.width, height = gwa.height;\n      int _x0 = x0, _y0 = y0, _x1 = x1, _y1 = y1;\n      if (_x0>_x1) cimg::swap(_x0,_x1);\n      if (_y0>_y1) cimg::swap(_y0,_y1);\n\n      XImage *image = 0;\n      if (_x1>=0 && _x0<width && _y1>=0 && _y0<height) {\n        _x0 = std::max(_x0,0);\n        _y0 = std::max(_y0,0);\n        _x1 = std::min(_x1,width - 1);\n        _y1 = std::min(_y1,height - 1);\n        image = XGetImage(dpy,root,_x0,_y0,_x1 - _x0 + 1,_y1 - _y0 + 1,AllPlanes,ZPixmap);\n\n        if (image) {","sourceCodeStart":11253,"sourceCodeEnd":11289,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L11253-L11289","documentation":"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.","triggerScenarios":"Thrown at ucrop/src/main/jni/CImg.h:11271 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set DISPLAY to a valid X server (e.g. :0) and confirm the server is running","Use a virtual X server such as Xvfb for headless screenshot capture","Grant X server access if connecting remotely (xhost + or proper X authorization cookies)"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}