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.
This commit is contained in:
Robert Osfield 2008-06-03 11:31:42 +00:00
parent 5711964481
commit ef601e6add

View File

@ -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)