Yalantis/uCrop · error · CImgArgumentException
displacement(): Invalid specified precision %g (should be…
Error message
displacement(): Invalid specified precision %g (should be >=0)
What it means
displacement() takes a precision parameter that controls the convergence threshold of the iterative optical-flow solver. Negative values are meaningless for this stopping criterion, so the library throws this CImgArgumentException when precision<0.
Solutions
- Pass a positive precision (the default is 5.0f); lower values give more precise but slower convergence
- Clamp the value before calling: if (precision < 0) precision = 0 (or a sensible default)
- Validate user/config input with a range check (precision >= 0) at parse time
- Check code that computes precision dynamically for sign errors
Example fix
// before img.displacement(ref, 0.1f, precision /* -1.f sentinel */); // after img.displacement(ref, 0.1f, precision < 0 ? 5.0f : precision);
Defensive patterns
Strategy: validation
Validate before calling
float precision = cfg.precision; if (precision < 0) precision = 5.0f; // library default CImg<float> flow = img.displacement(reference, smoothness, precision);
Try / catch
try {
CImg<float> flow = img.displacement(reference, smoothness, precision);
} catch (CImgArgumentException& e) {
std::fprintf(stderr, "precision must be >=0: %s\n", e.what());
CImg<float> flow = img.displacement(reference); // default precision=5
} Prevention
- Clamp precision to >=0 right after reading it from config/user input
- Avoid -1 sentinel values flowing into numeric parameters
- Remember lower precision values mean slower but more accurate convergence
- Use named defaults (5.0f) instead of ad-hoc magic numbers
When it happens
Trigger: Calling displacement() with a negative precision argument, e.g. displacement(ref, smoothness, -1.0f), typically from a miscalculation, a sign error, or an unvalidated user/config value.
Common situations: Config files where precision was meant as an offset or tolerance and a negative value was entered, variables initialized with -1 as a sentinel and passed unmodified, or unit confusion (pixels vs subpixels).
Related errors
- "[" cimg_appname "_math_parser] CImg<
- "[" cimg_appname "_math_parser] CImg<
- "[" cimg_appname "_math_parser] CImg<
- "[" cimg_appname "_math_parser] CImg<
- "[" cimg_appname "_math_parser] CImg<
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/a334235c57d362fc.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:45966
move_to(*this);
}
//! Estimate displacement field between two images \newinstance.
CImg<floatT> get_displacement(const CImg<T>& reference,
const float smoothness=0.1f, const float precision=5.f,
const unsigned int nb_scales=0, const unsigned int iteration_max=1000,
const bool is_forward=false,
const CImg<floatT>& guide=CImg<floatT>::const_empty()) const {
if (is_empty() || !reference) return +*this;
if (!is_sameXYZC(reference))
throw CImgArgumentException(_cimg_instance
"displacement(): Instance and reference image (%u,%u,%u,%u,%p) have "
"different dimensions.",
cimg_instance,
reference._width,reference._height,reference._depth,reference._spectrum,
reference._data);
if (precision<0)
throw CImgArgumentException(_cimg_instance
"displacement(): Invalid specified precision %g "
"(should be >=0)",
cimg_instance,
precision);
const bool is_3d = reference._depth>1;
const unsigned int spectrum_U = is_3d?3:2;
if (guide &&
(guide._width!=_width || guide._height!=_height || guide._depth!=_depth || guide._spectrum<spectrum_U))
throw CImgArgumentException(_cimg_instance
"displacement(): Specified guide (%u,%u,%u,%u,%p) "
"has invalid dimensions.",
cimg_instance,
guide._width,guide._height,guide._depth,guide._spectrum,guide._data);
const float
scale_factor = 2.f,
abs_smoothness = cimg::abs(smoothness),View on GitHub (pinned to f788b534b4)