{"record":{"id":"8968b34621846b97","repo":"Yalantis/uCrop","slug":"display-empty-specified-image","errorCode":null,"errorMessage":"display(): Empty specified image.","messagePattern":"display\\(\\): Empty specified image\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":12505,"sourceCode":"      return *this;\n    }\n\n    CImgDisplay& set_mouse(const int posx, const int posy) {\n      if (is_empty() || _is_closed || posx<0 || posy<0) return *this;\n      if (!_is_closed) {\n        cimg::SDL3_attr &SDL3_attr = cimg::SDL3_attr::ref();\n        SDL3_attr.lock();\n        SDL_WarpMouseInWindow(_window,(float)posx,(float)posy);\n        _mouse_x = posx; _mouse_y = posy;\n        SDL3_attr.unlock();\n      }\n      return *this;\n    }\n\n    template<typename T>\n    CImgDisplay& display(const CImg<T>& img) {\n      if (!img)\n        throw CImgArgumentException(_cimgdisplay_instance\n                                    \"display(): Empty specified image.\",\n                                    cimgdisplay_instance);\n      if (is_empty()) return assign(img);\n      return render(img).paint();\n    }\n\n    CImgDisplay& paint() {\n      if (_is_closed) return *this;\n      cimg::SDL3_attr &SDL3_attr = cimg::SDL3_attr::ref();\n\n      const SDL_ThreadID current_thread_id = SDL_GetCurrentThreadID();\n      if (current_thread_id!=_thread_id) {\n        // Make sure repaint is done by the thread that created the window.\n        _paint_request = true;\n        return *this;\n      }\n\n      SDL3_attr.lock();","sourceCodeStart":12487,"sourceCodeEnd":12523,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L12487-L12523","documentation":"CImgDisplay::display(const CImg<T>&) throws CImgArgumentException when the image passed to it is empty (operator bool() is false because _width/_height are 0). The display cannot render a zero-sized image, so the library refuses early instead of rendering nothing. It is a caller-supplied argument problem, not a display or window problem.","triggerScenarios":"Calling display(img) where img was default-constructed, assign()-reset, constructed with a 0 dimension, or where a previous load/assign operation silently failed and left the image empty.","commonSituations":"Loading a corrupted or missing image file and passing the result straight to display(); guarding code that checks only the pointer and not the image dimensions; reusing an image object after assign() without re-loading.","solutions":["Check the image with if (img) before calling display().","Fix the code path that produces the empty image (failed load, bad file, zero-sized crop) so a valid image reaches display().","If an empty display is legitimate, call is_empty()/assign() on the CImgDisplay instead of displaying an empty image."],"exampleFix":"// before\nCImg<unsigned char> img; // never filled\ndisp.display(img); // throws\n// after\nCImg<unsigned char> img(\"input.png\");\nif (img) disp.display(img);","handlingStrategy":"validation","validationCode":"if (!img) { /* image is empty: width or height is 0 */ return; }\ndisp.display(img);","typeGuard":"bool nonEmpty(const cimg_library::CImg<T>& img) { return (bool)img; } // true iff _width>0 && _height>0","tryCatchPattern":"try { disp.display(img); }\ncatch (cimg_library::CImgArgumentException &e) { fprintf(stderr, \"%s\", e.what()); }","preventionTips":["Always check operator bool() on images produced by load/crop before displaying.","Never reuse an image after assign() without re-populating it.","Centralize display calls behind a helper that validates emptiness."],"tags":["cimg","empty-image","argument-validation"],"backgroundTag":"empty-required-field","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"}