Yalantis/uCrop · error · CImgIOException

cimg::stdout(): Reference to 'stdout' stream not allowed in…

Error message

cimg::stdout(): Reference to 'stdout' stream not allowed in R mode ('cimg_use_r' is defined).

What it means

cimg::stdout() in an R-mode build (cimg_use_r defined) refuses to return the raw stdout FILE*, because writing to it bypasses R's output plumbing and can garble or crash the R session. With throw_exception true, it throws CImgIOException.

Solutions

  1. Use Rprintf/Rconsolemsg (R API) for output instead of cimg::stdout() in R-mode builds.
  2. Disable verbose CImg output (cimg::verbosity(0)) so code paths never request stdout.
  3. Build without cimg_use_r if direct stdio access is required.
  4. Catch CImgIOException and redirect output through R's supported channels.

Example fix

// before
std::FILE* out = cimg::stdout(); // throws in R mode
// after
#ifdef cimg_use_r
Rprintf("%s", msg.c_str());
#else
std::fprintf(cimg::stdout(), "%s", msg.c_str());
#endif
Defensive patterns

Strategy: try-catch

Validate before calling

bool stdoutAllowed() {
#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* out = cimg::stdout();
} catch (CImgIOException& e) {
  // R mode: print via Rprintf instead
}

Prevention

When it happens

Trigger: Calling cimg::stdout() (directly or via CImg features that print, verbose logging, or progress output) in a build compiled with cimg_use_r.

Common situations: Porting standalone CImg applications into an R package; enabling verbose/debug CImg output inside R sessions; code that caches cimg::stdout() at module init.

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


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/125927324ad33c7f. Report an issue: GitHub.

Appendix: source

Thrown at ucrop/src/main/jni/CImg.h:69119

      return stdin;
#else
      if (throw_exception) {
        cimg::exception_mode(0);
        throw CImgIOException("cimg::stdin(): Reference to 'stdin' stream not allowed in R mode "
                              "('cimg_use_r' is defined).");
      }
      return 0;
#endif
    }

    inline FILE* _stdout(const bool throw_exception) {
#ifndef cimg_use_r
      cimg::unused(throw_exception);
      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

View on GitHub (pinned to f788b534b4)