{"record":{"id":"62de7d5b9ab97be4","repo":"Yalantis/uCrop","slug":"draw-triangle-specified-color-is-null","errorCode":null,"errorMessage":"draw_triangle(): Specified color is (null).","messagePattern":"draw_triangle\\(\\): Specified color is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":50695,"sourceCode":"    //! Draw a filled 2D triangle.\n    /**\n       \\param x0 X-coordinate of the first vertex.\n       \\param y0 Y-coordinate of the first vertex.\n       \\param x1 X-coordinate of the second vertex.\n       \\param y1 Y-coordinate of the second vertex.\n       \\param x2 X-coordinate of the third vertex.\n       \\param y2 Y-coordinate of the third vertex.\n       \\param color Pointer to \\c spectrum() consecutive values of type \\c T, defining the drawing color.\n       \\param opacity Drawing opacity.\n     **/\n    template<typename tc>\n    CImg<T>& draw_triangle(const int x0, const int y0,\n                           const int x1, const int y1,\n                           const int x2, const int y2,\n                           const tc *const color, const float opacity=1) {\n      if (is_empty()) return *this;\n      if (!color)\n        throw CImgArgumentException(_cimg_instance\n                                    \"draw_triangle(): Specified color is (null).\",\n                                    cimg_instance);\n      _draw_triangle(x0,y0,x1,y1,x2,y2,color,opacity,1);\n      return *this;\n    }\n\n    //! Draw a outlined 2D triangle.\n    /**\n       \\param x0 X-coordinate of the first vertex.\n       \\param y0 Y-coordinate of the first vertex.\n       \\param x1 X-coordinate of the second vertex.\n       \\param y1 Y-coordinate of the second vertex.\n       \\param x2 X-coordinate of the third vertex.\n       \\param y2 Y-coordinate of the third vertex.\n       \\param color Pointer to \\c spectrum() consecutive values of type \\c T, defining the drawing color.\n       \\param opacity Drawing opacity.\n       \\param pattern An integer whose bits describe the outline pattern.\n     **/","sourceCodeStart":50677,"sourceCodeEnd":50713,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L50677-L50713","documentation":"Argument guard in CImg<T>::draw_triangle(): the 'color' parameter is a null pointer, but the renderer needs spectrum() consecutive color values of type T to fill the triangle, so there is no color to draw with.","triggerScenarios":"Calling draw_triangle with color==nullptr, typically from an uninitialized pointer or a null-returning color lookup.","commonSituations":"Mesh rendering helpers where material color failed to load; templated drawing code forwarding optional tc* colors.","solutions":["Pass a valid color array sized >= image.spectrum().","Guard with if (color) before the draw call.","Default to a fixed color when the requested one is unavailable.","Fix the upstream color producer to never return null on expected paths."],"exampleFix":"// before\nimg.draw_triangle(0,0, 50,10, 25,60, matColor, 1.0f); // matColor==nullptr\n// after\nunsigned char fallback[3] = {128,128,128};\nimg.draw_triangle(0,0, 50,10, 25,60, matColor?matColor:fallback, 1.0f);","handlingStrategy":"type-guard","validationCode":"if (!color) {\n  static const unsigned char red[3] = {255,0,0};\n  color = red;\n}\nimg.draw_triangle(x0,y0, x1,y1, x2,y2, color, opacity);","typeGuard":"template<typename T> bool nonNullColor(const T* c) { return c != nullptr; }","tryCatchPattern":"try {\n  img.draw_triangle(x0,y0, x1,y1, x2,y2, color, opacity);\n} catch (const cimg_library::CImgArgumentException& e) {\n  std::fprintf(stderr, \"draw_triangle: %s\\n\", e.what());\n}","preventionTips":["Resolve material colors at load time with fallbacks so null never propagates.","Use fixed-size color buffers instead of raw pointers in render helpers.","Unit-test drawing helpers with deliberately null inputs."],"tags":["cimg","null-pointer","triangle","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-17T15:17:12.973Z"}