Yalantis/uCrop · error · CImgArgumentException
draw_spline(): Specified color is (null).
Error message
draw_spline(): Specified color is (null).
What it means
draw_spline() with endpoint tangents (x0,y0,u0,v0)-(x1,y1,u1,v1) validates that the color pointer is non-null before rasterizing the spline. A null color makes pixel output impossible, so CImgArgumentException is thrown.
Source
Thrown at ucrop/src/main/jni/CImg.h:50430
The starting and ending velocities (\p u0,\p v0) and (\p u1,\p v1) can be deduced easily from
the control points as
\p u0 = (\p xa - \p x0), \p v0 = (\p ya - \p y0), \p u1 = (\p x1 - \p xb) and \p v1 = (\p y1 - \p yb).
\par Example:
\code
CImg<unsigned char> img(100,100,1,3,0);
const unsigned char color[] = { 255,255,255 };
img.draw_spline(30,30,0,100,90,40,0,-100,color);
\endcode
**/
template<typename tc>
CImg<T>& draw_spline(const int x0, const int y0, const float u0, const float v0,
const int x1, const int y1, const float u1, const float v1,
const tc *const color, const float opacity=1,
const float precision=0.25, const unsigned int pattern=~0U,
const bool init_hatch=true) {
if (is_empty()) return *this;
if (!color)
throw CImgArgumentException(_cimg_instance
"draw_spline(): Specified color is (null).",
cimg_instance);
if (x0==x1 && y0==y1) return draw_point(x0,y0,color,opacity);
bool ninit_hatch = init_hatch;
const float
ax = u0 + u1 + 2*(x0 - x1),
bx = 3*(x1 - x0) - 2*u0 - u1,
ay = v0 + v1 + 2*(y0 - y1),
by = 3*(y1 - y0) - 2*v0 - v1,
_precision = 1/(cimg::hypot((float)x0 - x1,(float)y0 - y1)*(precision>0?precision:1));
int ox = x0, oy = y0;
for (float t = 0; t<1; t+=_precision) {
const float t2 = t*t, t3 = t2*t;
const int
nx = (int)(ax*t3 + bx*t2 + u0*t + x0),
ny = (int)(ay*t3 + by*t2 + v0*t + y0);
draw_line(ox,oy,nx,ny,color,opacity,pattern,ninit_hatch);
ninit_hatch = false;View on GitHub (pinned to f788b534b4)
Solutions
- Pass a valid color array with at least image.spectrum() elements.
- Guard the call with if (color) before draw_spline.
- Provide a default color constant in your rendering helper.
- Audit the color producer for null-returning error paths.
Example fix
// before
img.draw_spline(0,0,0,0,100,100,0,0,nullptr,1.0f);
// after
const unsigned char color[3] = {0,200,120};
img.draw_spline(0,0,0,0,100,100,0,0,color,1.0f); Defensive patterns
Strategy: type-guard
Validate before calling
if (!color) {
static const unsigned char blue[3] = {0,0,255};
color = blue;
}
img.draw_spline(x0,y0,u0,v0,x1,y1,u1,v1, color, opacity, precision); Type guard
template<typename T> bool hasColor(const T* color) { return color != nullptr; } Try / catch
try {
img.draw_spline(x0,y0,u0,v0,x1,y1,u1,v1, color, opacity);
} catch (const cimg_library::CImgArgumentException& e) {
std::fprintf(stderr, "draw_spline: %s\n", e.what());
} Prevention
- Resolve colors to defaults before calling drawing APIs.
- Avoid raw owning pointers for colors; use arrays or std::vector with data() after size check.
- Test color-loading failure paths so null never reaches draw calls.
When it happens
Trigger: Calling draw_spline(x0,y0,u0,v0,x1,y1,u1,v1,color,...) with color==nullptr; same root causes as any null color pointer: failed lookup, uninitialized buffer, optional parameter forwarded as null.
Common situations: Curved path rendering where color comes from a theme/config that failed to load; templated code where tc* is null on a fallback path.
Related errors
- cimg::fopen(): Specified file path is (null).
- cimg::fopen(): File '%s', specified mode is (null).
- cimg::fread(): Invalid reading request of %u %s%s from file
- cimg::fwrite(): Invalid writing request of %u %s%s from buff
- cimg::fempty(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/cfce2172ff36f72b.
Report an issue: GitHub.