From b0ea5ed4da709312910898fa03b4dafc7a27e358 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 1 Jul 2022 14:02:28 -0400 Subject: Fix for issue with redirecting stdout/err to a file (#2311) --- source/core/slang-std-writers.h | 16 ++++++++++++++++ source/core/slang-writer.cpp | 9 +++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'source/core') diff --git a/source/core/slang-std-writers.h b/source/core/slang-std-writers.h index d193bfe0c..84447186a 100644 --- a/source/core/slang-std-writers.h +++ b/source/core/slang-std-writers.h @@ -15,6 +15,9 @@ public: ISlangWriter* getWriter(SlangWriterChannel chan) const { return m_writers[chan]; } void setWriter(SlangWriterChannel chan, ISlangWriter* writer) { m_writers[chan] = writer; } + /// Flush all the set writers + void flushWriters(); + /// Ctor StdWriters() {} @@ -36,6 +39,19 @@ protected: static StdWriters* s_singleton; }; +// -------------------------------------------------------------------------- +inline void StdWriters::flushWriters() +{ + for (Index i = 0; i < Count(SLANG_WRITER_CHANNEL_COUNT_OF); ++i) + { + auto writer = m_writers[i]; + if (writer) + { + writer->flush(); + } + } +} + } #endif diff --git a/source/core/slang-writer.cpp b/source/core/slang-writer.cpp index 849cb2da0..2b00b5853 100644 --- a/source/core/slang-writer.cpp +++ b/source/core/slang-writer.cpp @@ -127,9 +127,14 @@ SlangResult CallbackWriter::write(const char* chars, size_t numChars) FileWriter::~FileWriter() { - if ((m_flags & WriterFlag::IsUnowned) == 0) + if (m_file) { - fclose(m_file); + ::fflush(m_file); + + if ((m_flags & WriterFlag::IsUnowned) == 0) + { + ::fclose(m_file); + } } } -- cgit v1.2.3