{"record":{"id":"48752ce62eb1bab5","repo":"Yalantis/uCrop","slug":"draw-point-specified-color-is-null","errorCode":null,"errorMessage":"draw_point(): Specified color is (null).","messagePattern":"draw_point\\(\\): Specified color is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":49848,"sourceCode":"       \\param y0 Y-coordinate of the point.\n       \\param z0 Z-coordinate of the point.\n       \\param color Pointer to \\c spectrum() consecutive values, defining the drawing color.\n       \\param opacity Drawing opacity.\n       \\note\n       - To set pixel values without clipping needs, you should use the faster CImg::operator()() function.\n       \\par Example:\n       \\code\n       CImg<unsigned char> img(100,100,1,3,0);\n       const unsigned char color[] = { 255,128,64 };\n       img.draw_point(50,50,color);\n       \\endcode\n    **/\n    template<typename tc>\n    CImg<T>& draw_point(const int x0, const int y0, const int z0,\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_point(): Specified color is (null).\",\n                                    cimg_instance);\n      if (x0>=0 && y0>=0 && z0>=0 && x0<width() && y0<height() && z0<depth()) {\n        const ulongT whd = (ulongT)_width*_height*_depth;\n        const float nopacity = cimg::abs(opacity), copacity = 1 - std::max(opacity,0.f);\n        T *ptrd = data(x0,y0,z0,0);\n        const tc *col = color;\n        if (opacity>=1) cimg_forC(*this,c) { *ptrd = (T)*(col++); ptrd+=whd; }\n        else cimg_forC(*this,c) { *ptrd = (T)(*(col++)*nopacity + *ptrd*copacity); ptrd+=whd; }\n      }\n      return *this;\n    }\n\n    //! Draw a 2D point \\simplification.\n    template<typename tc>\n    CImg<T>& draw_point(const int x0, const int y0,\n                        const tc *const color, const float opacity=1) {\n      return draw_point(x0,y0,0,color,opacity);","sourceCodeStart":49830,"sourceCodeEnd":49866,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L49830-L49866","documentation":"CImg's draw_point() requires a pointer to a color array whose length matches the image spectrum. The library throws CImgArgumentException when the color pointer is null, because there is nothing to draw with.","triggerScenarios":"Calling img.draw_point(x,y,z, NULL) or passing a pointer variable that was never assigned / was set to null after a failed allocation or empty vector.","commonSituations":"Conditionally-built color arrays left null; passing nullptr as a placeholder assuming opacity-only drawing is allowed; a vector resized to zero and its data() pointer passed through.","solutions":["Always pass a valid array of at least spectrum() elements, e.g. const unsigned char col[3] = {255,0,0}; for an RGB image.","If the color is optional in your code, assign a default color before the draw call instead of passing null.","Check the pointer for null before calling and return/log an error early."],"exampleFix":"// before\nconst float *color = palette.empty() ? nullptr : palette[0].data();\nimg.draw_point(x, y, z, color); // throws when palette empty\n// after\nconst float default_color[3] = {255.0f, 255.0f, 255.0f};\nconst float *color = palette.empty() ? default_color : palette[0].data();\nimg.draw_point(x, y, z, color);","handlingStrategy":"validation","validationCode":"if (!color) {\n  throw std::invalid_argument(\"draw_point requires a non-null color array\");\n}\nif (img.spectrum() > 0 && sizeof(*color) >= 0) { /* ensure array has spectrum() elements */ }","typeGuard":null,"tryCatchPattern":"try {\n  img.draw_point(x, y, z, color);\n} catch (const cimg_library::CImgArgumentException& e) {\n  std::cerr << \"draw_point: \" << e.what() << std::endl;\n}","preventionTips":["Always pass a stack array sized to the image spectrum (e.g. col[3] for RGB)","Never use nullptr as a 'skip color' placeholder — CImg has no such convention","Guard vector-derived color pointers against empty containers","Check that color allocation succeeded before drawing"],"tags":["cimg","drawing","null-pointer","argument"],"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"}