{"record":{"id":"cfce2172ff36f72b","repo":"Yalantis/uCrop","slug":"draw-spline-specified-color-is-null","errorCode":null,"errorMessage":"draw_spline(): Specified color is (null).","messagePattern":"draw_spline\\(\\): Specified color is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":50430,"sourceCode":"       The starting and ending velocities (\\p u0,\\p v0) and (\\p u1,\\p v1) can be deduced easily from\n       the control points as\n       \\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).\n       \\par Example:\n       \\code\n       CImg<unsigned char> img(100,100,1,3,0);\n       const unsigned char color[] = { 255,255,255 };\n       img.draw_spline(30,30,0,100,90,40,0,-100,color);\n       \\endcode\n    **/\n    template<typename tc>\n    CImg<T>& draw_spline(const int x0, const int y0, const float u0, const float v0,\n                         const int x1, const int y1, const float u1, const float v1,\n                         const tc *const color, const float opacity=1,\n                         const float precision=0.25, const unsigned int pattern=~0U,\n                         const bool init_hatch=true) {\n      if (is_empty()) return *this;\n      if (!color)\n        throw CImgArgumentException(_cimg_instance\n                                    \"draw_spline(): Specified color is (null).\",\n                                    cimg_instance);\n      if (x0==x1 && y0==y1) return draw_point(x0,y0,color,opacity);\n      bool ninit_hatch = init_hatch;\n      const float\n        ax = u0 + u1 + 2*(x0 - x1),\n        bx = 3*(x1 - x0) - 2*u0 - u1,\n        ay = v0 + v1 + 2*(y0 - y1),\n        by = 3*(y1 - y0) - 2*v0 - v1,\n        _precision = 1/(cimg::hypot((float)x0 - x1,(float)y0 - y1)*(precision>0?precision:1));\n      int ox = x0, oy = y0;\n      for (float t = 0; t<1; t+=_precision) {\n        const float t2 = t*t, t3 = t2*t;\n        const int\n          nx = (int)(ax*t3 + bx*t2 + u0*t + x0),\n          ny = (int)(ay*t3 + by*t2 + v0*t + y0);\n        draw_line(ox,oy,nx,ny,color,opacity,pattern,ninit_hatch);\n        ninit_hatch = false;","sourceCodeStart":50412,"sourceCodeEnd":50448,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L50412-L50448","documentation":"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.","triggerScenarios":"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.","commonSituations":"Curved path rendering where color comes from a theme/config that failed to load; templated code where tc* is null on a fallback path.","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."],"exampleFix":"// before\nimg.draw_spline(0,0,0,0,100,100,0,0,nullptr,1.0f);\n// after\nconst unsigned char color[3] = {0,200,120};\nimg.draw_spline(0,0,0,0,100,100,0,0,color,1.0f);","handlingStrategy":"type-guard","validationCode":"if (!color) {\n  static const unsigned char blue[3] = {0,0,255};\n  color = blue;\n}\nimg.draw_spline(x0,y0,u0,v0,x1,y1,u1,v1, color, opacity, precision);","typeGuard":"template<typename T> bool hasColor(const T* color) { return color != nullptr; }","tryCatchPattern":"try {\n  img.draw_spline(x0,y0,u0,v0,x1,y1,u1,v1, color, opacity);\n} catch (const cimg_library::CImgArgumentException& e) {\n  std::fprintf(stderr, \"draw_spline: %s\\n\", e.what());\n}","preventionTips":["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."],"tags":["cimg","null-pointer","spline","argument-validation"],"backgroundTag":"null-argument","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}