Yalantis/uCrop · error · CImgArgumentException
draw_graph(): Specified color is (null).
Error message
draw_graph(): Specified color is (null).
What it means
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.
Source
Thrown at ucrop/src/main/jni/CImg.h:53404
- 3 = Diagonal cross.
- 4 = Filled circle.
- 5 = Outlined circle.
- 6 = Square.
- 7 = Diamond.
\param ymin Lower bound of the y-range.
\param ymax Upper bound of the y-range.
\param pattern Drawing pattern.
\note
- if \c ymin==ymax==0, the y-range is computed automatically from the input samples.
**/
template<typename t, typename tc>
CImg<T>& draw_graph(const CImg<t>& data,
const tc *const color, const float opacity=1,
const unsigned int plot_type=1, const int vertex_type=1,
const double ymin=0, const double ymax=0, const unsigned int pattern=~0U) {
if (is_empty() || _height<=1) return *this;
if (!color)
throw CImgArgumentException(_cimg_instance
"draw_graph(): Specified color is (null).",
cimg_instance);
// Create shaded colors for displaying bar plots.
CImg<tc> color1, color2;
if (plot_type==3) {
color1.assign(_spectrum); color2.assign(_spectrum);
cimg_forC(*this,c) {
color1[c] = (tc)std::min((float)cimg::type<tc>::max(),(float)color[c]*1.2f);
color2[c] = (tc)(color[c]*0.4f);
}
}
// Compute min/max and normalization factors.
const ulongT
siz = data.size(),
_siz1 = siz - (plot_type!=3),
siz1 = _siz1?_siz1:1;View on GitHub (pinned to f788b534b4)
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.
Example fix
// before
img.draw_graph(profile,getColorOpt(),1,1,1);
// after
const unsigned char* c = getColorOpt();
if (!c) { static const unsigned char def[3]={255,255,0}; c=def; }
img.draw_graph(profile,c,1,1,1); Defensive patterns
Strategy: validation
Validate before calling
if (!color) color = defaultPlotColor; img.draw_graph(data,color,opacity,plot_type,vertex_type);
Type guard
template<typename T> bool hasPlotColor(const T* c){ return c != nullptr; } Try / catch
try { img.draw_graph(data,color); }
catch (CImgArgumentException& e) { log_error("draw_graph: %s", e.what()); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Palette lookup failure returning null; refactored signatures where the color argument shifted position; JNI/managed bindings passing null byte[] for the plot color.
Related errors
- draw_rectangle(): Specified color is (null).
- draw_polygon(): Specified color is (null).
- draw_ellipse(): Specified color is (null).
- draw_circle(): Specified color is (null).
- draw_gaussian(): Specified color is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/a3382a87efa541bf.
Report an issue: GitHub.