From ef601e6adddbfe4e7187131e9ebb1dce5f654a85 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 3 Jun 2008 11:31:42 +0000 Subject: [PATCH] From Marco Lehmann and Robert Osfield, this fix was implemented by Robert but is based on suggested fix from Marco for fixing a crash due to lack of thread safety in std::ofstream("/dev/null"); The fix is to use a custom stream buffer that just discards all data. The implementation is also twice as fast as the old /dev/null based approach. --- src/osg/Notify.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/osg/Notify.cpp b/src/osg/Notify.cpp index 75a37c452..7351f7527 100644 --- a/src/osg/Notify.cpp +++ b/src/osg/Notify.cpp @@ -83,16 +83,20 @@ bool osg::isNotifyEnabled( osg::NotifySeverity severity ) return severity<=g_NotifyLevel; } -#if defined(WIN32) && !(defined(__CYGWIN__) || defined(__MINGW32__)) -const char* NullStreamName = "nul"; -#else -const char* NullStreamName = "/dev/null"; -#endif +class NullStreamBuffer : public std::streambuf +{ + private: + + virtual streamsize xsputn (const char_type*, streamsize n) + { + return n; + } +}; std::ostream& osg::notify(const osg::NotifySeverity severity) { // set up global notify null stream for inline notify - static std::ofstream s_NotifyNulStream(NullStreamName); + static std::ostream s_NotifyNulStream(new NullStreamBuffer()); static bool initialized = false; if (!initialized)