{"record":{"id":"34508044495fa5b6","repo":"Yalantis/uCrop","slug":"display-graph-empty-instance","errorCode":null,"errorMessage":"display_graph(): Empty instance.","messagePattern":"display_graph\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":61123,"sourceCode":"    }\n\n    //! Display 1D graph in an interactive window \\overloading.\n    const CImg<T>& display_graph(const char *const title=0,\n                                 const unsigned int plot_type=1, const unsigned int vertex_type=1,\n                                 const char *const labelx=0, const double xmin=0, const double xmax=0,\n                                 const char *const labely=0, const double ymin=0, const double ymax=0,\n                                 const bool exit_on_anykey=false) const {\n      CImgDisplay disp;\n      return _display_graph(disp,title,plot_type,vertex_type,labelx,xmin,xmax,labely,ymin,ymax,exit_on_anykey);\n    }\n\n    const CImg<T>& _display_graph(CImgDisplay &disp, const char *const title=0,\n                                  const unsigned int plot_type=1, const unsigned int vertex_type=1,\n                                  const char *const labelx=0, const double xmin=0, const double xmax=0,\n                                  const char *const labely=0, const double ymin=0, const double ymax=0,\n                                  const bool exit_on_anykey=false) const {\n      if (is_empty())\n        throw CImgInstanceException(_cimg_instance\n                                    \"display_graph(): Empty instance.\",\n                                    cimg_instance);\n      if (!disp) disp.assign(cimg_fitscreen(CImgDisplay::screen_width()/2,CImgDisplay::screen_height()/2,1),0,0).\n                   set_title(title?\"%s\":\"CImg<%s>\",title?title:pixel_type());\n      const ulongT siz = (ulongT)_width*_height*_depth, siz1 = std::max((ulongT)1,siz - 1);\n      const unsigned int old_normalization = disp.normalization();\n      disp.show().flush()._normalization = 0;\n\n      double y0 = ymin, y1 = ymax, nxmin = xmin, nxmax = xmax;\n      if (nxmin==nxmax) { nxmin = 0; nxmax = siz1; }\n      int x0 = 0, x1 = width()*height()*depth() - 1, key = 0;\n\n      for (bool reset_view = true; !key && !disp.is_closed(); ) {\n        if (reset_view) { x0 = 0; x1 = width()*height()*depth() - 1; y0 = ymin; y1 = ymax; reset_view = false; }\n        CImg<T> zoom(x1 - x0 + 1,1,1,spectrum());\n        cimg_forC(*this,c) zoom.get_shared_channel(c) = CImg<T>(data(x0,0,0,c),x1 - x0 + 1,1,1,1,true);\n        if (y0==y1) { y0 = zoom.min_max(y1); const double dy = y1 - y0; y0-=dy/20; y1+=dy/20; }\n        if (y0==y1) { --y0; ++y1; }","sourceCodeStart":61105,"sourceCodeEnd":61141,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L61105-L61141","documentation":"Thrown by the graph-display routines (_display_graph/display_graph) when the CImg instance whose data should be plotted is empty — it has no pixels/values to draw. The method needs at least one data point to construct a graph, so an empty (default-constructed or failed-load) image cannot be visualized. Fill the instance with data before calling display_graph().","triggerScenarios":"Calling display_graph() on a CImg constructed empty (CImg<T>()), on a crop that selected zero pixels, or on an image loaded from an empty file.","commonSituations":"Plotting a histogram of an empty ROI, plotting data from a failed load that returned an empty instance, slice extraction with inverted coordinates producing zero-size image.","solutions":["Check img.is_empty() before calling display_graph().","Verify the data-loading/cropping step actually produced pixels.","Populate the instance with the values to plot before displaying.","Use a fallback message/plot when data is empty instead of displaying."],"exampleFix":"// before\nimg.display_graph(\"values\");\n// after\nif (!img.is_empty()) img.display_graph(\"values\");\nelse cimg::warn(\"No data to plot.\");","handlingStrategy":"validation","validationCode":"if (img.is_empty()) { cimg::warn(\"Nothing to plot\"); return; }","typeGuard":null,"tryCatchPattern":"try { img.display_graph(); } catch (CImgInstanceException& e) { /* plot fallback / show message */ }","preventionTips":["Check is_empty() after load/crop before plotting","Validate ROI/slice coordinates produce non-zero size","Handle failed loads by aborting the plot pipeline early"],"tags":["cimg","display","empty-data","plot"],"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"}