{"record":{"id":"dda86cec24bcfedc","repo":"Yalantis/uCrop","slug":"cimg-stdin-reference-to-stdin-stream-not-all","errorCode":null,"errorMessage":"cimg::stdin(): Reference to 'stdin' stream not allowed in R mode ('cimg_use_r' is defined).","messagePattern":"cimg::stdin\\(\\): Reference to 'stdin' stream not allowed in R mode \\('cimg_use_r' is defined\\)\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":69105,"sourceCode":"    }\n\n    //@}\n  }; // struct CImgList { ...\n\n  // Completion of previously declared functions.\n  //---------------------------------------------\n  namespace cimg {\n\n    // Functions to return standard streams 'stdin', 'stdout' and 'stderr'.\n    // (throw a CImgIOException when macro 'cimg_use_r' is defined).\n    inline FILE* _stdin(const bool throw_exception) {\n#ifndef cimg_use_r\n      cimg::unused(throw_exception);\n      return stdin;\n#else\n      if (throw_exception) {\n        cimg::exception_mode(0);\n        throw CImgIOException(\"cimg::stdin(): Reference to 'stdin' stream not allowed in R mode \"\n                              \"('cimg_use_r' is defined).\");\n      }\n      return 0;\n#endif\n    }\n\n    inline FILE* _stdout(const bool throw_exception) {\n#ifndef cimg_use_r\n      cimg::unused(throw_exception);\n      return stdout;\n#else\n      if (throw_exception) {\n        cimg::exception_mode(0);\n        throw CImgIOException(\"cimg::stdout(): Reference to 'stdout' stream not allowed in R mode \"\n                              \"('cimg_use_r' is defined).\");\n      }\n      return 0;\n#endif","sourceCodeStart":69087,"sourceCodeEnd":69123,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L69087-L69123","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove/replace code that reads from stdin when building with cimg_use_r.","Rely on R's own input functions (readline/menu) instead of CImg stdin access.","If you genuinely need stdio access, build without cimg_use_r.","Wrap the call in try/catch (CImgIOException) and supply an alternative input source."],"exampleFix":"// before\nstd::FILE* in = cimg::stdin(); // throws in R mode\n// after\n#ifdef cimg_use_r\nSEXP in = R_GetConsoleInput(); // R-native input\n#else\nstd::FILE* in = cimg::stdin();\n#endif","handlingStrategy":"try-catch","validationCode":"bool stdinAllowed() {\n#ifndef cimg_use_r\n  return true;\n#else\n  return false;\n#endif\n}","typeGuard":"bool stdioAvailable() { return\n#ifndef cimg_use_r\n  true;\n#else\n  false;\n#endif\n}","tryCatchPattern":"try {\n  std::FILE* in = cimg::stdin();\n} catch (CImgIOException& e) {\n  // R mode: use R-native input instead\n}","preventionTips":["Guard stdio calls with #ifndef cimg_use_r.","Use R APIs (R API console functions) in R-mode builds.","Avoid interactive stdin prompts in embedded R contexts."],"tags":["r-integration","stdio","build-configuration","native"],"backgroundTag":"unsupported-platform","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}