Yalantis/uCrop · error · CImgInstanceException

display(): Empty instance.

Error message

display(): Empty instance.

What it means

CImgList::_display() throws CImgInstanceException when the list is empty (is_empty()); there are no images to render in the display window. It is an instance-state check, raised only when display windows are enabled (cimg_display != 0).

Solutions

  1. Check list.size() (or !list.is_empty()) before calling display().
  2. Ensure the preceding load/assignment actually populated the list.
  3. Guard display calls in headless environments where loads may be skipped.

Example fix

// before
list.display("result"); // throws if empty
// after
if (!list.is_empty()) list.display("result");
Defensive patterns

Strategy: validation

Validate before calling

if (list.is_empty()) {
  fprintf(stderr, "Nothing to display\n");
  return false;
}

Try / catch

try { list.display("result"); }
catch (CImgInstanceException &e) { fprintf(stderr, "Display skipped: %s\n", e.what()); }

Prevention

When it happens

Trigger: Calling .display() or .display_graph() etc. on a default-constructed CImgList, on a list after .clear()/.assign(), or on a list whose load() failed silently and left 0 images.

Common situations: Displaying results of a failed/optional file load in headless-deployed code path; iterating files where some produce empty lists; forgetting that a filtered/extracted list can be empty.

Related errors


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

Appendix: source

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

      \param axis Appending axis. Can be <tt>{ 'x' | 'y' | 'z' | 'c' }</tt>.
      \param align Appending alignment.
      \param[in,out] XYZ Contains the XYZ coordinates at start / exit of the function.
      \param exit_on_anykey Exit function when any key is pressed.
    **/
    const CImgList<T>& display(const char *const title=0, const bool display_info=true,
                               const char axis='x', const float align=0,
                               unsigned int *const XYZ=0, const bool exit_on_anykey=false) const {
      CImgDisplay disp;
      bool is_exit = false;
      return _display(disp,title,0,display_info,axis,align,XYZ,exit_on_anykey,0,true,is_exit);
    }

    const CImgList<T>& _display(CImgDisplay &disp, const char *const title, const CImgList<charT> *const titles,
                                const bool display_info, const char axis, const float align, unsigned int *const XYZ,
                                const bool exit_on_anykey, const unsigned int orig, const bool is_first_call,
                                bool &is_exit) const {
      if (is_empty())
        throw CImgInstanceException(_cimglist_instance
                                    "display(): Empty instance.",
                                    cimglist_instance);
      if (!disp) {
        if (axis=='x') {
          unsigned int sum_width = 0, max_height = 0;
          cimglist_for(*this,l) {
            const CImg<T> &img = _data[l];
            const unsigned int
              w = CImgDisplay::_fitscreen(img._width,img._height,img._depth,128,-85,false),
              h = CImgDisplay::_fitscreen(img._width,img._height,img._depth,128,-85,true);
            sum_width+=w;
            if (h>max_height) max_height = h;
          }
          disp.assign(cimg_fitscreen(sum_width,max_height,1),title?title:titles?titles->__display()._data:0,1);
        } else {
          unsigned int max_width = 0, sum_height = 0;
          cimglist_for(*this,l) {
            const CImg<T> &img = _data[l];

View on GitHub (pinned to f788b534b4)