Yalantis/uCrop · error · CImgIOException
cimg::stderr(): Reference to 'stderr' stream not allowed in…
Error message
cimg::stderr(): Reference to 'stderr' stream not allowed in R mode ('cimg_use_r' is defined). What it means
cimg::stderr() in an R-mode build (cimg_use_r defined) throws CImgIOException when asked for the raw stderr FILE*, since R must own error/diagnostic output; writing to stderr directly bypasses R's error handling. It sets exception_mode(0) before throwing so CImg does not double-report.
Solutions
- Route diagnostics through R's REprintf/error() API instead of cimg::stderr().
- Adjust cimg::exception_mode() / output settings so code does not request stderr in R mode.
- Build without cimg_use_r if native stdio diagnostics are required.
- Catch CImgIOException around diagnostics-triggering calls.
Example fix
// before
std::FILE* err = cimg::stderr(); // throws in R mode
// after
#ifdef cimg_use_r
REprintf("%s", diag.c_str());
#else
std::fprintf(cimg::stderr(), "%s", diag.c_str());
#endif Defensive patterns
Strategy: try-catch
Validate before calling
bool stderrAllowed() {
#ifndef cimg_use_r
return true;
#else
return false;
#endif
} Type guard
bool stdioAvailable() { return
#ifndef cimg_use_r
true;
#else
false;
#endif
} Try / catch
try {
std::FILE* err = cimg::stderr();
} catch (CImgIOException& e) {
// R mode: use REprintf / error() instead
} Prevention
- Use R's REprintf/error API for diagnostics in R-mode builds.
- Set cimg::exception_mode() appropriately for embedded contexts.
- Guard stdio with preprocessor checks.
When it happens
Trigger: Calling cimg::stderr() directly, or triggering CImg code paths that report warnings/errors to stderr, inside a cimg_use_r build with throw_exception enabled.
Common situations: CImg exception/warning handlers in R-mode builds; porting command-line CImg tools into R; debug builds that log diagnostics to cimg::stderr().
Understand the failure class
Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.
Related errors
- cimg::stdin(): Reference to 'stdin' stream not allowed in R…
- cimg::stdout(): Reference to 'stdout' stream not allowed in…
- CImgList< >::get_unserialize(): Unable to unserialize…
- CImgDisplay(): No display available.
- CImgList< >::get_unserialize(): CImg header not found in…
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/c4ff850f4fb6210c.
Report an issue: GitHub.
Appendix: source
Thrown at ucrop/src/main/jni/CImg.h:69133
return stdout;
#else
if (throw_exception) {
cimg::exception_mode(0);
throw CImgIOException("cimg::stdout(): Reference to 'stdout' stream not allowed in R mode "
"('cimg_use_r' is defined).");
}
return 0;
#endif
}
inline FILE* _stderr(const bool throw_exception) {
#ifndef cimg_use_r
cimg::unused(throw_exception);
return stderr;
#else
if (throw_exception) {
cimg::exception_mode(0);
throw CImgIOException("cimg::stderr(): Reference to 'stderr' stream not allowed in R mode "
"('cimg_use_r' is defined).");
}
return 0;
#endif
}
// Open a file (similar to std:: fopen(), but with wide character support on Windows).
inline std::FILE *std_fopen(const char *const path, const char *const mode) {
std::FILE *const res = std::fopen(path,mode);
if (res) return res;
#if cimg_OS==2
// Try alternative method, with wide-character string.
int err = MultiByteToWideChar(CP_UTF8,0,path,-1,0,0);
if (err) {
CImg<wchar_t> wpath((unsigned int)err);
err = MultiByteToWideChar(CP_UTF8,0,path,-1,wpath,err);
if (err) { // Convert 'mode' to a wide-character string
err = MultiByteToWideChar(CP_UTF8,0,mode,-1,0,0);View on GitHub (pinned to f788b534b4)