{"record":{"id":"826efd98c61729d5","repo":"Yalantis/uCrop","slug":"load-rgb-specified-filename-is-null","errorCode":null,"errorMessage":"load_rgb(): Specified filename is (null).","messagePattern":"load_rgb\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57869,"sourceCode":"    //! Load image from a RGB file \\newinstance.\n    static CImg<T> get_load_rgb(const char *const filename, const unsigned int dimw, const unsigned int dimh=1) {\n      return CImg<T>().load_rgb(filename,dimw,dimh);\n    }\n\n    //! Load image from a RGB file \\overloading.\n    CImg<T>& load_rgb(std::FILE *const file, const unsigned int dimw, const unsigned int dimh=1) {\n      return _load_rgb(file,0,dimw,dimh);\n    }\n\n    //! Load image from a RGB file \\newinstance.\n    static CImg<T> get_load_rgb(std::FILE *const file, const unsigned int dimw, const unsigned int dimh=1) {\n      return CImg<T>().load_rgb(file,dimw,dimh);\n    }\n\n    CImg<T>& _load_rgb(std::FILE *const file, const char *const filename,\n                       const unsigned int dimw, const unsigned int dimh) {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_rgb(): Specified filename is (null).\",\n                                    cimg_instance);\n\n      if (!dimw || !dimh) return assign();\n      const longT cimg_iobuffer = (longT)24*1024*1024;\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"rb\");\n      CImg<ucharT> raw;\n      assign(dimw,dimh,1,3);\n      T\n        *ptr_r = data(0,0,0,0),\n        *ptr_g = data(0,0,0,1),\n        *ptr_b = data(0,0,0,2);\n      for (longT to_read = (longT)size(); to_read>0; ) {\n        raw.assign(std::min(to_read,cimg_iobuffer));\n        cimg::fread(raw._data,raw._width,nfile);\n        to_read-=raw._width;\n        const unsigned char *ptrs = raw._data;\n        for (ulongT off = raw._width/3UL; off; --off) {","sourceCodeStart":57851,"sourceCodeEnd":57887,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57851-L57887","documentation":"CImg<T>::_load_rgb() reads raw interleaved RGB bytes from a FILE* or a named file. Like the other raw loaders it requires one of the two sources; if both the FILE* and filename are null it throws CImgArgumentException because there is no input stream to read.","triggerScenarios":"Calling load_rgb(nullptr, w, h) or _load_rgb with a NULL filename; a path variable from a failed lookup (getenv/config) that is NULL; invoking the FILE*-overload before opening the file.","commonSituations":"Raw framebuffer/video-frame loaders where the file path comes from configuration that was never set; uninitialized char* filename; pipeline stages passing through empty paths.","solutions":["Pass a valid filename: img.load_rgb(\"frame.rgb\", w, h).","Open the file first and pass the FILE* handle to load_rgb.","Null-check/guard the path before the call and provide a default or clear error.","Trace why the configured path resolved to NULL (missing config key, failed env lookup).","Catch CImgArgumentException where paths are user-supplied and optional."],"exampleFix":"// before\nFILE* f = NULL;\nimg.load_rgb(f, dimw, dimh); // never opened\n// after\nFILE* f = std::fopen(\"frame.rgb\", \"rb\");\nif (f) {\n  img.load_rgb(f, dimw, dimh);\n  std::fclose(f);\n}","handlingStrategy":"type-guard","validationCode":"if (path == nullptr || path[0] == '\\0') {\n  throw std::invalid_argument(\"RGB path must be set before load_rgb\");\n}","typeGuard":"bool hasSource(std::FILE* f, const char* name) { return f != nullptr || name != nullptr; }","tryCatchPattern":"try {\n  img.load_rgb(path, dimw, dimh);\n} catch (cimg_library::CImgArgumentException& e) {\n  std::cerr << \"No RGB source given: \" << e.what() << \"\\n\";\n}","preventionTips":["Null-check the source of raw-frame paths before loading","Use std::string paths to avoid dangling/NULL char*","Open FILE* handles before FILE*-overload calls","Require dimension args (dimw/dimh) come from validated config"],"tags":["cimg","raw-rgb","null-argument","image-loading"],"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"}