{"record":{"id":"2fdbfea537131836","repo":"Yalantis/uCrop","slug":"select-graph-empty-instance","errorCode":null,"errorMessage":"select_graph(): Empty instance.","messagePattern":"select_graph\\(\\): Empty instance\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":56177,"sourceCode":"        else {\n          const float\n            m = (float)cimg::type<T>::min(),\n            M = (float)cimg::type<T>::max();\n          (img2d-=m)*=255.f/(M - m>0?M - m:1);\n        } break;\n      }\n      if (img2d.spectrum()==2) img2d.channels(0,2);\n      return img2d;\n    }\n\n    //! Select sub-graph in a graph.\n    CImg<intT> get_select_graph(CImgDisplay &disp,\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                                    \"select_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(\"CImg<%s>\",pixel_type());\n      const ulongT siz = (ulongT)_width*_height*_depth;\n      const unsigned int old_normalization = disp.normalization();\n      disp.show().set_button().set_wheel()._normalization = 0;\n\n      double nymin = ymin, nymax = ymax, nxmin = xmin, nxmax = xmax;\n      if (nymin==nymax) { nymin = (Tfloat)min_max(nymax); const double dy = nymax - nymin; nymin-=dy/20; nymax+=dy/20; }\n      if (nymin==nymax) { --nymin; ++nymax; }\n      if (nxmin==nxmax && nxmin==0) { nxmin = 0; nxmax = siz - 1.; }\n\n      static const unsigned char black[] = { 0, 0, 0 }, white[] = { 255, 255, 255 }, gray[] = { 220, 220, 220 };\n      static const unsigned char gray2[] = { 110, 110, 110 }, ngray[] = { 35, 35, 35 };\n\n      CImg<ucharT> colormap(3,_spectrum);\n      if (_spectrum==1) { colormap[0] = colormap[1] = 120; colormap[2] = 200; }","sourceCodeStart":56159,"sourceCodeEnd":56195,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L56159-L56195","documentation":"get_select_graph() opens an interactive display to let the user select a graph plot of the image data. It is a non-const-sensitive instance method requiring actual pixel data; calling it on an empty CImg instance throws CImgInstanceException before any display work happens.","triggerScenarios":"Calling select_graph()/get_select_graph() on a default-constructed CImg, on an instance after assign() (which empties it), or after a failed load() left the image empty.","commonSituations":"Load failure path not checked (file missing) followed by interactive selection; constructing the image conditionally so one branch leaves it empty; reusing a variable that was reassigned to an empty image.","solutions":["Check img.is_empty() (or !img) before calling select_graph().","Verify the preceding load()/assign() succeeded before invoking display-based methods.","Initialize the image with real data (load a file or allocate dimensions) before interactive selection."],"exampleFix":"// before\nCImg<float> img; // empty\nimg.select_graph();\n// after\nCImg<float> img(\"data.png\");\nif (!img.is_empty()) img.select_graph();","handlingStrategy":"type-guard","validationCode":"if (img.is_empty()) {\n  std::cerr << \"Cannot select graph on empty image\" << std::endl;\n  return;\n}\nimg.select_graph();","typeGuard":"bool readyForGraph(const cimg_library::CImg<float>& img) { return !img.is_empty(); }","tryCatchPattern":"try {\n  img.select_graph();\n} catch (const cimg_library::CImgInstanceException& e) {\n  std::cerr << \"Empty image: \" << e.what() << std::endl;\n}","preventionTips":["Check is_empty() after every load/assign before display-based methods","Treat load failure as terminal for downstream interactive calls","Construct images with real data before entering UI code paths"],"tags":["cimg","empty-instance","display"],"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"}