Yalantis/uCrop · error · CImgArgumentException

display(): Empty specified image.

Error message

display(): Empty specified image.

What it means

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.

Source

Thrown at ucrop/src/main/jni/CImg.h:12505

      return *this;
    }

    CImgDisplay& set_mouse(const int posx, const int posy) {
      if (is_empty() || _is_closed || posx<0 || posy<0) return *this;
      if (!_is_closed) {
        cimg::SDL3_attr &SDL3_attr = cimg::SDL3_attr::ref();
        SDL3_attr.lock();
        SDL_WarpMouseInWindow(_window,(float)posx,(float)posy);
        _mouse_x = posx; _mouse_y = posy;
        SDL3_attr.unlock();
      }
      return *this;
    }

    template<typename T>
    CImgDisplay& display(const CImg<T>& img) {
      if (!img)
        throw CImgArgumentException(_cimgdisplay_instance
                                    "display(): Empty specified image.",
                                    cimgdisplay_instance);
      if (is_empty()) return assign(img);
      return render(img).paint();
    }

    CImgDisplay& paint() {
      if (_is_closed) return *this;
      cimg::SDL3_attr &SDL3_attr = cimg::SDL3_attr::ref();

      const SDL_ThreadID current_thread_id = SDL_GetCurrentThreadID();
      if (current_thread_id!=_thread_id) {
        // Make sure repaint is done by the thread that created the window.
        _paint_request = true;
        return *this;
      }

      SDL3_attr.lock();

View on GitHub (pinned to f788b534b4)

Solutions

  1. Check the image with if (img) before calling display().
  2. Fix the code path that produces the empty image (failed load, bad file, zero-sized crop) so a valid image reaches display().
  3. If an empty display is legitimate, call is_empty()/assign() on the CImgDisplay instead of displaying an empty image.

Example fix

// before
CImg<unsigned char> img; // never filled
disp.display(img); // throws
// after
CImg<unsigned char> img("input.png");
if (img) disp.display(img);
Defensive patterns

Strategy: validation

Validate before calling

if (!img) { /* image is empty: width or height is 0 */ return; }
disp.display(img);

Type guard

bool nonEmpty(const cimg_library::CImg<T>& img) { return (bool)img; } // true iff _width>0 && _height>0

Try / catch

try { disp.display(img); }
catch (cimg_library::CImgArgumentException &e) { fprintf(stderr, "%s", e.what()); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/8968b34621846b97. Report an issue: GitHub.