{"record":{"id":"c4ff850f4fb6210c","repo":"Yalantis/uCrop","slug":"cimg-stderr-reference-to-stderr-stream-not-a","errorCode":null,"errorMessage":"cimg::stderr(): Reference to 'stderr' stream not allowed in R mode ('cimg_use_r' is defined).","messagePattern":"cimg::stderr\\(\\): Reference to 'stderr' 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":69133,"sourceCode":"      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\n    }\n\n    // Open a file (similar to std:: fopen(), but with wide character support on Windows).\n    inline std::FILE *std_fopen(const char *const path, const char *const mode) {\n      std::FILE *const res = std::fopen(path,mode);\n      if (res) return res;\n#if cimg_OS==2\n      // Try alternative method, with wide-character string.\n      int err = MultiByteToWideChar(CP_UTF8,0,path,-1,0,0);\n      if (err) {\n        CImg<wchar_t> wpath((unsigned int)err);\n        err = MultiByteToWideChar(CP_UTF8,0,path,-1,wpath,err);\n        if (err) { // Convert 'mode' to a wide-character string\n          err = MultiByteToWideChar(CP_UTF8,0,mode,-1,0,0);","sourceCodeStart":69115,"sourceCodeEnd":69151,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L69115-L69151","documentation":"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.","triggerScenarios":"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.","commonSituations":"CImg exception/warning handlers in R-mode builds; porting command-line CImg tools into R; debug builds that log diagnostics to cimg::stderr().","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."],"exampleFix":"// before\nstd::FILE* err = cimg::stderr(); // throws in R mode\n// after\n#ifdef cimg_use_r\nREprintf(\"%s\", diag.c_str());\n#else\nstd::fprintf(cimg::stderr(), \"%s\", diag.c_str());\n#endif","handlingStrategy":"try-catch","validationCode":"bool stderrAllowed() {\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* err = cimg::stderr();\n} catch (CImgIOException& e) {\n  // R mode: use REprintf / error() instead\n}","preventionTips":["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."],"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"}