{"record":{"id":"125927324ad33c7f","repo":"Yalantis/uCrop","slug":"cimg-stdout-reference-to-stdout-stream-not-a","errorCode":null,"errorMessage":"cimg::stdout(): Reference to 'stdout' stream not allowed in R mode ('cimg_use_r' is defined).","messagePattern":"cimg::stdout\\(\\): Reference to 'stdout' 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":69119,"sourceCode":"      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\n    }\n\n    inline FILE* _stderr(const bool throw_exception) {\n#ifndef cimg_use_r\n      cimg::unused(throw_exception);\n      return stderr;\n#else\n      if (throw_exception) {\n        cimg::exception_mode(0);\n        throw CImgIOException(\"cimg::stderr(): Reference to 'stderr' stream not allowed in R mode \"\n                              \"('cimg_use_r' is defined).\");\n      }\n      return 0;\n#endif","sourceCodeStart":69101,"sourceCodeEnd":69137,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L69101-L69137","documentation":"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.","triggerScenarios":"Calling cimg::stdout() (directly or via CImg features that print, verbose logging, or progress output) in a build compiled with cimg_use_r.","commonSituations":"Porting standalone CImg applications into an R package; enabling verbose/debug CImg output inside R sessions; code that caches cimg::stdout() at module init.","solutions":["Use Rprintf/Rconsolemsg (R API) for output instead of cimg::stdout() in R-mode builds.","Disable verbose CImg output (cimg::verbosity(0)) so code paths never request stdout.","Build without cimg_use_r if direct stdio access is required.","Catch CImgIOException and redirect output through R's supported channels."],"exampleFix":"// before\nstd::FILE* out = cimg::stdout(); // throws in R mode\n// after\n#ifdef cimg_use_r\nRprintf(\"%s\", msg.c_str());\n#else\nstd::fprintf(cimg::stdout(), \"%s\", msg.c_str());\n#endif","handlingStrategy":"try-catch","validationCode":"bool stdoutAllowed() {\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* out = cimg::stdout();\n} catch (CImgIOException& e) {\n  // R mode: print via Rprintf instead\n}","preventionTips":["Route all logging through an abstraction that picks Rprintf vs stdio at compile time.","Disable CImg verbosity in R-mode builds.","Guard direct stdio usage with preprocessor checks."],"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"}