Yalantis/uCrop · error · CImgArgumentException
load_magick(): Specified filename is (null).
Error message
load_magick(): Specified filename is (null).
What it means
load_magick() validates its filename argument first: a NULL pointer cannot name any file, so CImg throws CImgArgumentException immediately. This is a caller programming error caught by defensive argument checking, thrown regardless of whether libMagick++ is enabled.
Source
Thrown at ucrop/src/main/jni/CImg.h:57266
if (ptr_a) *(ptr_a++) = (T)*(ptrs++);
}
}
} break;
}
JxlDecoderDestroy(decoder);
return *this;
#endif
}
//! Load image from a file, using Magick++ library.
/**
\param filename Filename, as a C-string.
**/
// Added April/may 2006 by Christoph Hormann <chris_hormann@gmx.de>.
// This is experimental code, not much tested, use with care.
CImg<T>& load_magick(const char *const filename) {
if (!filename)
throw CImgArgumentException(_cimg_instance
"load_magick(): Specified filename is (null).",
cimg_instance);
#ifdef cimg_use_magick
Magick::Image image(filename);
const unsigned int W = image.size().width(), H = image.size().height();
switch (image.type()) {
case Magick::PaletteMatteType :
case Magick::TrueColorMatteType :
case Magick::ColorSeparationType : {
assign(W,H,1,4);
T *ptr_r = data(0,0,0,0), *ptr_g = data(0,0,0,1), *ptr_b = data(0,0,0,2), *ptr_a = data(0,0,0,3);
Magick::PixelPacket *pixels = image.getPixels(0,0,W,H);
for (ulongT off = (ulongT)W*H; off; --off) {
*(ptr_r++) = (T)(pixels->red);
*(ptr_g++) = (T)(pixels->green);
*(ptr_b++) = (T)(pixels->blue);
*(ptr_a++) = (T)(pixels->opacity);View on GitHub (pinned to f788b534b4)
Solutions
- Ensure a non-NULL filename string is passed; check the source of the path before calling.
- Provide a default path when the lookup can fail (e.g. getenv fallback).
- Switch to std::string-based handling so empty/absent paths are caught before the C-string boundary.
Example fix
// before
const char* p = getenv("IMG_PATH");
img.load_magick(p); // NULL if unset
// after
const char* p = getenv("IMG_PATH");
if (p) img.load_magick(p); else img.load_magick("/default/img.png"); Defensive patterns
Strategy: validation
Validate before calling
bool validPath(const char* p) { return p != nullptr && p[0] != '\0'; } Try / catch
try { img.load_magick(path); } catch (CImgArgumentException& e) { log("null filename passed to load_magick"); } Prevention
- Never pass C-strings from lookups (getenv, find) without a NULL check
- Prefer std::string in your API and .c_str() only at the boundary
- Assert non-null filenames in debug builds before image loads
When it happens
Trigger: Calling CImg<T>::load_magick(NULL), or passing the result of a lookup function that returned NULL (e.g. getenv of an unset var, failed path resolution).
Common situations: Path taken from a missing environment variable or failed string conversion; uninitialized char* members; C APIs returning NULL for 'not found' passed straight through.
Related errors
- load_jpeg(): Specified filename is (null).
- load_jxl(): Specified filename is (null).
- load_pfm(): Specified filename is (null).
- load_rgb(): Specified filename is (null).
- load_rgba(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/edda7c414e4d5b4a.
Report an issue: GitHub.