{"record":{"id":"a3382a87efa541bf","repo":"Yalantis/uCrop","slug":"draw-graph-specified-color-is-null","errorCode":null,"errorMessage":"draw_graph(): Specified color is (null).","messagePattern":"draw_graph\\(\\): Specified color is \\(null\\)\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":53404,"sourceCode":"                      - 3 = Diagonal cross.\n                      - 4 = Filled circle.\n                      - 5 = Outlined circle.\n                      - 6 = Square.\n                      - 7 = Diamond.\n       \\param ymin Lower bound of the y-range.\n       \\param ymax Upper bound of the y-range.\n       \\param pattern Drawing pattern.\n       \\note\n         - if \\c ymin==ymax==0, the y-range is computed automatically from the input samples.\n    **/\n    template<typename t, typename tc>\n    CImg<T>& draw_graph(const CImg<t>& data,\n                        const tc *const color, const float opacity=1,\n                        const unsigned int plot_type=1, const int vertex_type=1,\n                        const double ymin=0, const double ymax=0, const unsigned int pattern=~0U) {\n      if (is_empty() || _height<=1) return *this;\n      if (!color)\n        throw CImgArgumentException(_cimg_instance\n                                    \"draw_graph(): Specified color is (null).\",\n                                    cimg_instance);\n\n      // Create shaded colors for displaying bar plots.\n      CImg<tc> color1, color2;\n      if (plot_type==3) {\n        color1.assign(_spectrum); color2.assign(_spectrum);\n        cimg_forC(*this,c) {\n          color1[c] = (tc)std::min((float)cimg::type<tc>::max(),(float)color[c]*1.2f);\n          color2[c] = (tc)(color[c]*0.4f);\n        }\n      }\n\n      // Compute min/max and normalization factors.\n      const ulongT\n        siz = data.size(),\n        _siz1 = siz - (plot_type!=3),\n        siz1 = _siz1?_siz1:1;","sourceCodeStart":53386,"sourceCodeEnd":53422,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L53386-L53422","documentation":"draw_graph() plots a 1D data series inside the image and requires a non-null color pointer, throwing CImgArgumentException when color is null. The color buffer must supply at least spectrum() channel values used for the plot line/bars; the routine also derives shaded variants (color1/color2) from it for bar plots, which is impossible with a null base color.","triggerScenarios":"img.draw_graph(data,NULL) or passing a color pointer that was never allocated/freed; optional color parameters threaded through from an outer API that defaulted to null; wrapper bindings forwarding null arrays.","commonSituations":"Palette lookup failure returning null; refactored signatures where the color argument shifted position; JNI/managed bindings passing null byte[] for the plot color.","solutions":["Pass a valid color array with spectrum() elements, e.g. const unsigned char col[]={200,30,30}.","Null-check and substitute a default color before the call.","Guard optional-color higher-level APIs so they materialize a concrete color rather than forwarding null.","In bindings, validate non-null color arrays at the boundary."],"exampleFix":"// before\nimg.draw_graph(profile,getColorOpt(),1,1,1);\n// after\nconst unsigned char* c = getColorOpt();\nif (!c) { static const unsigned char def[3]={255,255,0}; c=def; }\nimg.draw_graph(profile,c,1,1,1);","handlingStrategy":"validation","validationCode":"if (!color) color = defaultPlotColor;\nimg.draw_graph(data,color,opacity,plot_type,vertex_type);","typeGuard":"template<typename T> bool hasPlotColor(const T* c){ return c != nullptr; }","tryCatchPattern":"try { img.draw_graph(data,color); }\ncatch (CImgArgumentException& e) { log_error(\"draw_graph: %s\", e.what()); }","preventionTips":["Default plot colors in one helper so callers never pass null.","Null-check colors obtained from lookups/caches before drawing.","Keep argument order documented when wrapping draw_graph.","Use static const color buffers to guarantee pointer validity."],"tags":["cimg","image-processing","null-pointer"],"backgroundTag":"null-argument","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"}