Yalantis/uCrop · error · CImgIOException

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

Error message

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

What it means

cimg::stdin() is compiled in R mode (cimg_use_r defined, used when CImg is embedded in the R package), where returning a raw stdio FILE* would corrupt R's console I/O management. When throw_exception is true, CImg sets exception_mode(0) (silent) and throws CImgIOException instead of returning stdin.

Solutions

  1. Remove/replace code that reads from stdin when building with cimg_use_r.
  2. Rely on R's own input functions (readline/menu) instead of CImg stdin access.
  3. If you genuinely need stdio access, build without cimg_use_r.
  4. Wrap the call in try/catch (CImgIOException) and supply an alternative input source.

Example fix

// before
std::FILE* in = cimg::stdin(); // throws in R mode
// after
#ifdef cimg_use_r
SEXP in = R_GetConsoleInput(); // R-native input
#else
std::FILE* in = cimg::stdin();
#endif
Defensive patterns

Strategy: try-catch

Validate before calling

bool stdinAllowed() {
#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* in = cimg::stdin();
} catch (CImgIOException& e) {
  // R mode: use R-native input instead
}

Prevention

When it happens

Trigger: Any code path in a cimg_use_r build that calls cimg::stdin() (directly or via APIs reading from standard input) with throw_exception enabled — e.g. interactive prompts or CImg display routines relying on stdin.

Common situations: Using CImg inside R (or an R-mode-configured build) with code written for standalone CImg that reads from stdin; porting desktop CImg code into an R package without removing stdio usage.

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/dda86cec24bcfedc. Report an issue: GitHub.

Appendix: source

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

    }

    //@}
  }; // struct CImgList { ...

  // Completion of previously declared functions.
  //---------------------------------------------
  namespace cimg {

    // Functions to return standard streams 'stdin', 'stdout' and 'stderr'.
    // (throw a CImgIOException when macro 'cimg_use_r' is defined).
    inline FILE* _stdin(const bool throw_exception) {
#ifndef cimg_use_r
      cimg::unused(throw_exception);
      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

View on GitHub (pinned to f788b534b4)