{"record":{"id":"adf512ef08a51f62","repo":"Yalantis/uCrop","slug":"draw-gaussian-specified-color-is-null","errorCode":null,"errorMessage":"draw_gaussian(): Specified color is (null).","messagePattern":"draw_gaussian\\(\\): Specified color is \\(null\\)\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":53891,"sourceCode":"                             const bool is_julia_set=false,\n                             const double param_r=0, const double param_i=0) {\n      return draw_mandelbrot(0,0,_width - 1,_height - 1,colormap,opacity,\n                             z0r,z0i,z1r,z1i,iteration_max,is_normalized_iteration,is_julia_set,param_r,param_i);\n    }\n\n    //! Draw a 1D gaussian function.\n    /**\n       \\param xc X-coordinate of the gaussian center.\n       \\param sigma Standard variation of the gaussian distribution.\n       \\param color Pointer to \\c spectrum() consecutive values, defining the drawing color.\n       \\param opacity Drawing opacity.\n    **/\n    template<typename tc>\n    CImg<T>& draw_gaussian(const float xc, const float sigma,\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_gaussian(): Specified color is (null).\",\n                                    cimg_instance);\n      const float sigma2 = 2*sigma*sigma, nopacity = cimg::abs(opacity), copacity = 1 - std::max(opacity,0.f);\n      const ulongT whd = (ulongT)_width*_height*_depth;\n      const tc *col = color;\n      cimg_forX(*this,x) {\n        const float dx = (x - xc), val = (float)std::exp(-dx*dx/sigma2);\n        T *ptrd = data(x,0,0,0);\n        if (opacity>=1) cimg_forC(*this,c) { *ptrd = (T)(val*(*col++)); ptrd+=whd; }\n        else cimg_forC(*this,c) { *ptrd = (T)(nopacity*val*(*col++) + *ptrd*copacity); ptrd+=whd; }\n        col-=_spectrum;\n      }\n      return *this;\n    }\n\n    //! Draw a 2D gaussian function.\n    /**\n       \\param xc X-coordinate of the gaussian center.","sourceCodeStart":53873,"sourceCodeEnd":53909,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L53873-L53909","documentation":"draw_gaussian() blends a 1D Gaussian profile along the x axis using a color buffer, and throws CImgArgumentException when the color pointer is null. The routine reads color values per column during blending, so a null pointer is rejected right after the empty-image early return. The buffer must provide at least spectrum() channel values.","triggerScenarios":"img.draw_gaussian(xc,sigma,NULL) with literal null; color pointer from an unassigned or freed allocation; wrapper/binding code passing a null array; wrong-overload confusion where the opacity value ends up in the color parameter position.","commonSituations":"Color resolved from a theme/palette that returned null; pipeline stages that pass optional colors through; JNI code calling with a null jbyteArray for the color.","solutions":["Pass a valid color array sized to img.spectrum(), e.g. const float col[1]={1.f} for grayscale.","Null-check the color at the call site and substitute a default or skip the draw.","Fix wrapper layers to reject or default null color arrays before entering CImg.","Confirm argument order when using the default opacity parameter so a numeric value isn't misread as color (template tc catches this at compile time only for non-pointer types)."],"exampleFix":"// before\nimg.draw_gaussian(mu,sigma,nullptr);\n// after\nconst unsigned char col[3] = {255,255,255};\nimg.draw_gaussian(mu,sigma,col);","handlingStrategy":"validation","validationCode":"if (!color) color = defaultGaussianColor;\nimg.draw_gaussian(xc,sigma,color,opacity);","typeGuard":"template<typename T> bool validGaussianColor(const T* c){ return c != nullptr; }","tryCatchPattern":"try { img.draw_gaussian(xc,sigma,color); }\ncatch (CImgArgumentException& e) { log_error(\"draw_gaussian: %s\", e.what()); }","preventionTips":["Never pass nullptr as color to CImg draw primitives.","Provide defaults for optional colors at the wrapper level, not inside native calls.","Match color channel count to image spectrum (1 for gray, 3 for RGB).","Null-check pointers returned by palette/theme lookups before use."],"tags":["cimg","image-processing","null-pointer"],"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"}