{"record":{"id":"bad660a6302087df","repo":"Yalantis/uCrop","slug":"cimg-sdl3-attr-s","errorCode":null,"errorMessage":"cimg::SDL3_attr(): %s","messagePattern":"cimg::SDL3_attr\\(\\): (.+?)","errorType":"exception","errorClass":"CImgDisplayException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":3359,"sourceCode":"\n      SDL3_attr():nb_cimg_displays(0),display(0),mode(0),mutex_lock_display(0) {\n        bool init_failed = true;\n        if (SDL_Init(SDL_INIT_VIDEO)) {\n          display = SDL_GetPrimaryDisplay();\n          if (display) {\n            mode = SDL_GetCurrentDisplayMode(display);\n            if (mode) {\n              mutex_lock_display = SDL_CreateMutex();\n              if (mutex_lock_display) init_failed = false;\n              main_thread_id = SDL_GetCurrentThreadID();\n            }\n          }\n        }\n#if cimg_OS==1\n        std::signal(SIGINT,SIG_DFL); // Restore default behavior for CTRL+C\n#endif\n        if (init_failed)\n          throw CImgDisplayException(\"cimg::SDL3_attr(): %s\",SDL_GetError());\n        cimg_displays = new CImgDisplay*[512];\n      }\n\n      ~SDL3_attr() {\n        unlock();\n        SDL_DestroyMutex(mutex_lock_display);\n        SDL_Quit();\n        delete[] cimg_displays;\n      }\n\n      SDL3_attr& lock() { // Lock display\n        SDL_LockMutex(mutex_lock_display);\n        return *this;\n      }\n\n      SDL3_attr& unlock() { // Unlock display\n        SDL_UnlockMutex(mutex_lock_display);\n        return *this;","sourceCodeStart":3341,"sourceCodeEnd":3377,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L3341-L3377","documentation":"CImg's SDL3_attr helper initializes the SDL display subsystem (SDL_Init(SDL_INIT_VIDEO/SDL3 backend)); if SDL init fails it throws CImgDisplayException carrying SDL_GetError(). This is an environment-level failure of the native display backend, not a problem with image data, and typically occurs the first time a CImgDisplay is constructed.","triggerScenarios":"Constructing a CImgDisplay (or any code path initializing the SDL3 display attribute) on a system where SDL_Init fails: no X11/Wayland display, missing SDL3 library, or headless CI/container without a virtual framebuffer.","commonSituations":"Building/running the uCrop native (JNI) code or its tests on a headless Linux build machine; SDL3 not installed or wrong version so cimg's SDL3 backend fails to load; running on Android where desktop display init is unsupported.","solutions":["Run in an environment with a display, or use Xvfb: xvfb-run ./your_binary.","Install the SDL3 development/runtime library that CImg's SDL backend expects.","Avoid code paths that create CImgDisplay in headless builds (guard display usage with cimg::display_info()/compile-time checks or disable display code).","For Android targets, do not initialize CImgDisplay — use CImg's image processing APIs only.","Check SDL_GetError() output embedded in the message for the concrete cause (driver/library/version)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const bool display_available = (std::getenv(\"DISPLAY\") != nullptr) || (std::getenv(\"WAYLAND_DISPLAY\") != nullptr);\nif (!display_available) {\n    std::fprintf(stderr, \"No display available; skipping CImgDisplay usage\\n\");\n    return; // skip display code path\n}","typeGuard":null,"tryCatchPattern":"try {\n    cimg_library::CImgDisplay disp(img, \"preview\");\n} catch (cimg_library::CImgDisplayException& e) {\n    std::fprintf(stderr, \"Display init failed: %s\\n\", e.what());\n    // fall back to headless processing: save image to file instead of showing\n}","preventionTips":["Run GUI code paths only on machines with an active display or Xvfb.","Install and version-match the SDL3 runtime expected by CImg's SDL backend.","Isolate CImgDisplay usage behind a compile-time or runtime flag for headless builds.","On Android/JNI targets, avoid CImgDisplay entirely; use only image-processing APIs.","Read SDL_GetError() from the exception message to pinpoint missing drivers/libs."],"tags":["cimg","jni","sdl3","display","initialization"],"backgroundTag":"module-init-failed","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}