Yalantis/uCrop · error · CImgArgumentException
draw_gaussian(): Specified color is (null).
Error message
draw_gaussian(): Specified color is (null).
What it means
draw_gaussian() blends a 1D Gaussian profile along the x axis using a color buffer, and throws CImgArgumentException when the color pointer is null. The routine reads color values per column during blending, so a null pointer is rejected right after the empty-image early return. The buffer must provide at least spectrum() channel values.
Source
Thrown at ucrop/src/main/jni/CImg.h:53891
const bool is_julia_set=false,
const double param_r=0, const double param_i=0) {
return draw_mandelbrot(0,0,_width - 1,_height - 1,colormap,opacity,
z0r,z0i,z1r,z1i,iteration_max,is_normalized_iteration,is_julia_set,param_r,param_i);
}
//! Draw a 1D gaussian function.
/**
\param xc X-coordinate of the gaussian center.
\param sigma Standard variation of the gaussian distribution.
\param color Pointer to \c spectrum() consecutive values, defining the drawing color.
\param opacity Drawing opacity.
**/
template<typename tc>
CImg<T>& draw_gaussian(const float xc, const float sigma,
const tc *const color, const float opacity=1) {
if (is_empty()) return *this;
if (!color)
throw CImgArgumentException(_cimg_instance
"draw_gaussian(): Specified color is (null).",
cimg_instance);
const float sigma2 = 2*sigma*sigma, nopacity = cimg::abs(opacity), copacity = 1 - std::max(opacity,0.f);
const ulongT whd = (ulongT)_width*_height*_depth;
const tc *col = color;
cimg_forX(*this,x) {
const float dx = (x - xc), val = (float)std::exp(-dx*dx/sigma2);
T *ptrd = data(x,0,0,0);
if (opacity>=1) cimg_forC(*this,c) { *ptrd = (T)(val*(*col++)); ptrd+=whd; }
else cimg_forC(*this,c) { *ptrd = (T)(nopacity*val*(*col++) + *ptrd*copacity); ptrd+=whd; }
col-=_spectrum;
}
return *this;
}
//! Draw a 2D gaussian function.
/**
\param xc X-coordinate of the gaussian center.View on GitHub (pinned to f788b534b4)
Solutions
- Pass a valid color array sized to img.spectrum(), e.g. const float col[1]={1.f} for grayscale.
- Null-check the color at the call site and substitute a default or skip the draw.
- Fix wrapper layers to reject or default null color arrays before entering CImg.
- Confirm argument order when using the default opacity parameter so a numeric value isn't misread as color (template tc catches this at compile time only for non-pointer types).
Example fix
// before
img.draw_gaussian(mu,sigma,nullptr);
// after
const unsigned char col[3] = {255,255,255};
img.draw_gaussian(mu,sigma,col); Defensive patterns
Strategy: validation
Validate before calling
if (!color) color = defaultGaussianColor; img.draw_gaussian(xc,sigma,color,opacity);
Type guard
template<typename T> bool validGaussianColor(const T* c){ return c != nullptr; } Try / catch
try { img.draw_gaussian(xc,sigma,color); }
catch (CImgArgumentException& e) { log_error("draw_gaussian: %s", e.what()); } Prevention
- Never pass nullptr as color to CImg draw primitives.
- Provide defaults for optional colors at the wrapper level, not inside native calls.
- Match color channel count to image spectrum (1 for gray, 3 for RGB).
- Null-check pointers returned by palette/theme lookups before use.
When it happens
Trigger: img.draw_gaussian(xc,sigma,NULL) with literal null; color pointer from an unassigned or freed allocation; wrapper/binding code passing a null array; wrong-overload confusion where the opacity value ends up in the color parameter position.
Common situations: Color resolved from a theme/palette that returned null; pipeline stages that pass optional colors through; JNI code calling with a null jbyteArray for the 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_graph(): Specified color is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/adf512ef08a51f62.
Report an issue: GitHub.