{"record":{"id":"71f4f6d2b824e369","repo":"Yalantis/uCrop","slug":"cimgdisplay-assign-s","errorCode":null,"errorMessage":"CImgDisplay::assign(): %s","messagePattern":"CImgDisplay::assign\\(\\): (.+?)","errorType":"exception","errorClass":"CImgDisplayException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":12113,"sourceCode":"      _height = std::min(dimh,(unsigned int)screen_height());\n      _normalization = normalization_type<4?normalization_type:3;\n      _is_fullscreen = is_fullscreen;\n      _window_x = _window_y = cimg::type<int>::min();\n      _is_closed = closed_flag;\n      _is_cursor_visible = true;\n      _paint_request = false;\n      _title = tmp_title;\n      _thread_id = SDL_GetCurrentThreadID();\n      flush();\n\n      // Create window and renderer.\n      if (!SDL_CreateWindowAndRenderer(_title,(int)_width,(int)_height,\n                                       SDL_WINDOW_RESIZABLE | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS |\n                                       (_is_fullscreen?SDL_WINDOW_FULLSCREEN:0) |\n                                       (_is_closed?SDL_WINDOW_HIDDEN:0),\n                                       &_window,&_renderer)) {\n        SDL3_attr.unlock();\n        throw CImgDisplayException(\"CImgDisplay::assign(): %s\",SDL_GetError());\n      }\n      SDL_RaiseWindow(_window);\n      SDL_SetRenderDrawColor(_renderer,0,0,0,255);\n      if (!_is_fullscreen)\n        SDL_SetWindowPosition(_window,SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED);\n      _window_width = _width;\n      _window_height = _height;\n      _update_window_pos();\n\n      // Create texture.\n      _texture = SDL_CreateTexture(_renderer,SDL_PIXELFORMAT_RGBA8888,SDL_TEXTUREACCESS_STREAMING,\n                                   (int)_width,(int)_height);\n      _data = new unsigned int[_width*_height];\n\n      // Add to managed list of CImgDisplays.\n      if (SDL3_attr.nb_cimg_displays>=512) {\n        SDL3_attr.unlock();\n        throw CImgDisplayException(\"CImgDisplay::assign(): Max number of displays (512) already opened.\");","sourceCodeStart":12095,"sourceCodeEnd":12131,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L12095-L12131","documentation":"CImgDisplay::assign() (SDL3 backend) throws CImgDisplayException containing the string returned by SDL_GetError() when SDL_CreateWindowAndRenderer fails to create the window/renderer. The %s is SDL's own diagnostic message, so the real cause is in SDL.","triggerScenarios":"Calling assign(width,height,title) (or constructing a CImgDisplay) when SDL video subsystem is not initialized, the requested window size is invalid (<=0), SDL was built without video support, or the platform cannot create a window/renderer.","commonSituations":"Forgetting cimg::SDL3_attr()/SDL_Init(SDL_INIT_VIDEO) before creating displays (headless servers, CI containers without X/Wayland), requesting a 0-sized window, SDL3 migration issues where the video driver is unavailable.","solutions":["Initialize SDL video before creating the display: SDL_Init(SDL_INIT_VIDEO) (or ensure CImg's SDL3 attribute init ran).","Read the SDL_GetError() text embedded in the message for the concrete SDL cause (e.g. 'Video subsystem has not been initialized').","Run on a machine with a working display server, or use a virtual framebuffer (xvfb) in CI/containers.","Pass positive non-zero width/height to assign()."],"exampleFix":"// before\nCImgDisplay disp(0, 0, \"win\"); // invalid size, throws with SDL_GetError()\n// after\nif (SDL_Init(SDL_INIT_VIDEO) == 0) {\n  CImgDisplay disp(640, 480, \"win\");\n} else {\n  std::fprintf(stderr, \"SDL init failed: %s\\n\", SDL_GetError());\n}","handlingStrategy":"try-catch","validationCode":"if (SDL_WasInit(SDL_INIT_VIDEO) == 0) SDL_Init(SDL_INIT_VIDEO); // ensure video subsystem before assign\nif (width <= 0 || height <= 0) width = height = 1;","typeGuard":null,"tryCatchPattern":"try { disp.assign(w, h, title); } catch (CImgDisplayException& e) { std::fprintf(stderr, \"window creation failed: %s\\n\", e.what()); }","preventionTips":["Initialize SDL video (SDL_INIT_VIDEO) before any CImgDisplay is created.","Use xvfb or a real display server in headless/CI environments.","Always pass positive window dimensions.","Log the SDL_GetError() text embedded in the exception message."],"tags":["cimg","sdl","window-creation","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"}