{"record":{"id":"f3d879d5b5a95ba4","repo":"Yalantis/uCrop","slug":"cimg-dialog-no-display-available","errorCode":null,"errorMessage":"cimg::dialog(): No display available.","messagePattern":"cimg::dialog\\(\\): No display available\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":70273,"sourceCode":"       \\param logo Image logo displayed at the left of the main message.\n       \\param is_centered Tells if the dialog window must be centered on the screen.\n       \\return Index of clicked button (from \\c 0 to \\c 5), or \\c -1 if the dialog window has been closed by the user.\n       \\note\n       - Up to 6 buttons can be defined in the dialog window.\n       - The function returns when a user clicked one of the button or closed the dialog window.\n       - If a button text is set to 0, the corresponding button (and the following) will not appear in the dialog box.\n       At least one button must be specified.\n    **/\n    template<typename t>\n    inline int dialog(const char *const title, const char *const msg,\n                      const char *const button1_label, const char *const button2_label,\n                      const char *const button3_label, const char *const button4_label,\n                      const char *const button5_label, const char *const button6_label,\n                      const CImg<t>& logo, const bool is_centered=false) {\n#if cimg_display==0\n      cimg::unused(title,msg,button1_label,button2_label,button3_label,button4_label,button5_label,button6_label,\n                   logo._data,is_centered);\n      throw CImgIOException(\"cimg::dialog(): No display available.\");\n#else\n      static const unsigned char\n        black[] = { 0,0,0 }, white[] = { 255,255,255 }, gray[] = { 200,200,200 }, gray2[] = { 150,150,150 };\n\n      // Create buttons and canvas graphics.\n      CImgList<unsigned char> buttons, cbuttons, sbuttons;\n      if (button1_label) {\n        CImg<unsigned char>().draw_text(0,0,button1_label,black,gray,1,13).move_to(buttons);\n        if (button2_label) {\n          CImg<unsigned char>().draw_text(0,0,button2_label,black,gray,1,13).move_to(buttons);\n          if (button3_label) {\n            CImg<unsigned char>().draw_text(0,0,button3_label,black,gray,1,13).move_to(buttons);\n            if (button4_label) {\n              CImg<unsigned char>().draw_text(0,0,button4_label,black,gray,1,13).move_to(buttons);\n              if (button5_label) {\n                CImg<unsigned char>().draw_text(0,0,button5_label,black,gray,1,13).move_to(buttons);\n                if (button6_label) {\n                  CImg<unsigned char>().draw_text(0,0,button6_label,black,gray,1,13).move_to(buttons);","sourceCodeStart":70255,"sourceCodeEnd":70291,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L70255-L70291","documentation":"cimg::dialog() renders a graphical message box with up to six buttons using the CImg display layer. When CImg was compiled without display support (cimg_display==0, i.e. no X11/Windows/GDI/SDL backend available at compile time) the function is a stub that immediately throws CImgIOException because there is no display to draw on.","triggerScenarios":"Calling cimg::dialog() (directly, or indirectly via functions that fall back to it, e.g. when an image cannot be loaded and CImg offers an interactive dialog) in a build where cimg_display is 0 — headless Linux servers, cross-compiled Android NDK builds (as in ucrop's JNI build), or projects compiled with -Dcimg_display=0.","commonSituations":"Running a GUI-using CImg program on a headless server/CI container built without X11 headers; Android NDK builds where no display backend exists; Docker images without X/libx11-dev installed; intentionally disabling display support for a library build but still calling interactive helpers.","solutions":["Replace cimg::dialog() with non-interactive reporting (log the message, fprintf/std::cerr, or your UI framework's dialog) when targeting headless platforms.","Check the environment before calling: if cimg_display==0 (or DISPLAY is unset on Linux), take an alternate code path instead of invoking the dialog.","If a display is expected, rebuild CImg with a display backend enabled (install X11 headers and compile with cimg_display=1, default) or run under X (e.g. xvfb) on headless machines.","In library code, never call cimg::dialog(); keep interactive UI out of library/JNI layers and surface errors to the caller instead."],"exampleFix":"// before\ncimg::dialog(\"Error\", \"Failed to load image\", \"OK\"); // throws on headless/Android builds\n// after\n#if cimg_display!=0\n  cimg::dialog(\"Error\", \"Failed to load image\", \"OK\");\n#else\n  fprintf(stderr, \"Failed to load image\\n\");\n#endif","handlingStrategy":"try-catch","validationCode":"// Detect headless/no-display builds before calling dialog\nbool hasDisplay() {\n#if cimg_display==0\n  return false;\n#else\n  const char* d = std::getenv(\"DISPLAY\");\n  return d != nullptr && *d != '\\0';\n#endif\n}\nif (!hasDisplay()) { fprintf(stderr, \"%s\\n\", msg); } else { cimg::dialog(title, msg, \"OK\"); }","typeGuard":null,"tryCatchPattern":"try {\n  cimg::dialog(\"Error\", msg, \"OK\");\n} catch (CImgIOException& e) {\n  // No display available: degrade to console logging\n  std::cerr << \"Dialog unavailable: \" << msg << \"\\n\";\n}","preventionTips":["Never use cimg::dialog() in library, JNI, server, or CI code; keep it in desktop GUI layers only.","Compile-time check cimg_display and provide a logging fallback branch for cimg_display==0 builds.","On headless Linux boxes, install xvfb and run with xvfb-run if interactive dialogs are truly needed.","Log the message via fprintf/std::cerr as the default path and treat dialogs as an optional enhancement."],"tags":["headless","no-display","gui","platform","cimg"],"backgroundTag":"unsupported-platform","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"}