Yalantis/uCrop · error · CImgArgumentException
draw_spline(): Invalid specified texture (%u,%u,%u,%u,%p).
Error message
draw_spline(): Invalid specified texture (%u,%u,%u,%u,%p).
What it means
draw_spline() with a texture validates texture._depth<=1 and texture._spectrum>=instance._spectrum. Textures must be flat 2D images with enough channels; otherwise CImgArgumentException reports the texture dimensions.
Source
Thrown at ucrop/src/main/jni/CImg.h:50483
\param tx0 X-coordinate of the starting texture point.
\param ty0 Y-coordinate of the starting texture point.
\param tx1 X-coordinate of the ending texture point.
\param ty1 Y-coordinate of the ending texture point.
\param precision Curve drawing precision.
\param opacity Drawing opacity.
\param pattern An integer whose bits describe the line pattern.
\param init_hatch if \c true, reinit hatch motif.
**/
template<typename t>
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 CImg<t>& texture,
const int tx0, const int ty0, const int tx1, const int ty1,
const float opacity=1,
const float precision=4, const unsigned int pattern=~0U,
const bool init_hatch=true) {
if (texture._depth>1 || texture._spectrum<_spectrum)
throw CImgArgumentException(_cimg_instance
"draw_spline(): Invalid specified texture (%u,%u,%u,%u,%p).",
cimg_instance,
texture._width,texture._height,texture._depth,texture._spectrum,texture._data);
if (is_empty()) return *this;
if (is_overlapped(texture))
return draw_spline(x0,y0,u0,v0,x1,y1,u1,v1,+texture,tx0,ty0,tx1,ty1,precision,opacity,pattern,init_hatch);
if (x0==x1 && y0==y1)
return draw_point(x0,y0,texture.get_vector_at(x0<=0?0:x0>=texture.width()?texture.width() - 1:x0,
y0<=0?0:y0>=texture.height()?texture.height() - 1:y0).data(),
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, otx = tx0, oty = ty0;View on GitHub (pinned to f788b534b4)
Solutions
- Flatten the texture to depth 1 and resize channels: tex.get_resize(tex.width(),tex.height(),1,img.spectrum()).
- Ensure the texture is 2D before passing.
- Match or exceed the image channel count in the texture.
- For overlap the library handles copies internally; only depth/spectrum need pre-checks.
Example fix
// before CImg<float> grad(128,128,1,1); // 1 channel img.draw_spline(x0,y0,u0,v0,x1,y1,u1,v1,grad,0,0,127,127,1.0f); // after CImg<float> grad3 = grad.get_resize(grad.width(),grad.height(),1,img.spectrum()); img.draw_spline(x0,y0,u0,v0,x1,y1,u1,v1,grad3,0,0,127,127,1.0f);
Defensive patterns
Strategy: validation
Validate before calling
if (texture.depth()>1 || texture.spectrum()<img.spectrum()) {
texture = texture.get_resize(-100,-100,1,img.spectrum());
}
img.draw_spline(x0,y0,u0,v0,x1,y1,u1,v1, texture, tx0,ty0,tx1,ty1, opacity, precision); Type guard
template<typename T, typename t>
bool isFlatSufficientTexture(const CImg<T>& img, const CImg<t>& tex) {
return tex.depth()<=1 && tex.spectrum()>=img.spectrum();
} Try / catch
try {
img.draw_spline(x0,y0,u0,v0,x1,y1,u1,v1, texture, tx0,ty0,tx1,ty1);
} catch (const cimg_library::CImgArgumentException& e) {
std::fprintf(stderr, "draw_spline texture: %s\n", e.what());
} Prevention
- Normalize all textures (depth 1, spectrum >= target) at load time.
- Reuse the same texture-validation helper for draw_line/draw_spline/draw_triangle.
- Check texture channels whenever image spectrum changes (e.g. switching to RGBA).
When it happens
Trigger: Passing a 3D (depth>1) image or a texture with fewer spectrum channels than the drawing image as the texture parameter of the tangent-based draw_spline overload.
Common situations: Gradient/gradient-map textures stored as volumes; grayscale gradient map used on an RGB image; texture loaded with wrong channel count.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- draw_spline(): Specified color is (null).
- draw_spline(): Invalid specified point set (%u,%u,%u,%u,%p).
- draw_triangle(): Invalid specified texture (%u,%u,%u,%u,%p).
- draw_triangle(): Invalid specified light texture (%u,%u,%u,%
- cimg::fopen(): Specified file path is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/93f7373327b90c51.
Report an issue: GitHub.