Yalantis/uCrop · error · CImgArgumentException
draw_line(): Invalid specified point set (%u,%u,%u,%u).
Error message
draw_line(): Invalid specified point set (%u,%u,%u,%u).
What it means
In the points-based draw_line(points,color,...) overload, the points image must have exactly height()==2 (two rows: x coordinates and y coordinates). Otherwise the point set is invalid and CImgArgumentException is thrown listing the points image dimensions.
Source
Thrown at ucrop/src/main/jni/CImg.h:50333
\param color Pointer to \c spectrum() consecutive values of type \c T, defining the drawing color.
\param opacity Drawing opacity.
\param pattern An integer whose bits describe the line pattern.
\param init_hatch If set to true, init hatch motif.
\note
- This function uses several call to the single CImg::draw_line() procedure,
depending on the vectors size in \p points.
**/
template<typename tp, typename tc>
CImg<T>& draw_line(const CImg<tp>& points,
const tc *const color, const float opacity=1,
const unsigned int pattern=~0U, const bool init_hatch=true) {
if (is_empty() || !points) return *this;
if (!color)
throw CImgArgumentException(_cimg_instance
"draw_line(): Specified color is (null).",
cimg_instance);
if (points.height()!=2)
throw CImgArgumentException(_cimg_instance
"draw_line(): Invalid specified point set (%u,%u,%u,%u).",
cimg_instance,
points._width,points._height,points._depth,points._spectrum);
CImg<intT> ipoints;
if (cimg::type<tp>::is_float()) ipoints = points.get_round();
else ipoints.assign(points,cimg::type<tp>::string()==cimg::type<int>::string());
bool ninit_hatch = init_hatch;
const int x0 = ipoints(0,0), y0 = ipoints(0,1);
int ox = x0, oy = y0;
for (unsigned int i = 1; i<ipoints._width; ++i) {
const int x = ipoints(i,0), y = ipoints(i,1);
draw_line(ox,oy,x,y,color,opacity,pattern,ninit_hatch);
ninit_hatch = false;
ox = x; oy = y;
}
return *this;
}View on GitHub (pinned to f788b534b4)
Solutions
- Reshape the point set to height 2: CImg<int> pts = points.get_resize(-100,2) or transpose appropriately.
- For a two-endpoint line, construct CImg<int>(2,2,1,1,x0,x1,y0,y1) (width=2, height=2).
- Use draw_polygon or draw_spline overloads if you actually need more than two points.
- Print points.width()/height() before the call to confirm layout.
Example fix
// before CImg<int> pts(2,10); // 2 cols x 10 rows -> height 10 img.draw_line(pts,color); // after CImg<int> pts = pts_wrong.get_transpose(); // height 2 img.draw_line(pts,color);
Defensive patterns
Strategy: validation
Validate before calling
if (points.height()!=2 || points.width()<2) {
throw std::invalid_argument("draw_line point set must be Wx2 with >=2 points");
}
img.draw_line(points, color, opacity); Type guard
template<typename T> bool isLinePointSet(const CImg<T>& pts) {
return pts.height()==2 && pts.width()>=2;
} Try / catch
try {
img.draw_line(points, color, opacity);
} catch (const cimg_library::CImgArgumentException& e) {
std::fprintf(stderr, "draw_line point set: %s\n", e.what());
} Prevention
- Remember the layout: height 2, x coords in row 0, y coords in row 1, one column per point.
- Transpose point matrices that come from Nx2 tabular data.
- Add a debug assert on points.height()==2 before drawing.
- Use distinct types/wrappers for line point sets vs polygon/spline point sets.
When it happens
Trigger: Passing a points image with height 1, 3, or more (e.g. a polyline point list Nx2 transposed wrongly, or an Nx3 set with z rows) to draw_line, which only accepts 2xN (or Nx2 stored as height 2).
Common situations: Building a points matrix as N rows x 2 columns instead of 2 rows x N columns; reusing a point set meant for draw_spline or draw_polygon; accidentally passing an image of pixels instead of a point set.
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(): Invalid specified point set (%u,%u,%u,%u,%p).
- 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
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/48ea1d7ae9bb8f55.
Report an issue: GitHub.