From 9d7f4523b0333b672edb650941453ea8c99e4cbc Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 9 Jan 2021 01:52:47 +1000 Subject: [PATCH] Log: Close C file handles on free (win32) Fixes toggling console not hiding the window. --- src/common/log.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/common/log.cpp b/src/common/log.cpp index ea5cd0bf2..07651bd58 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -229,6 +229,15 @@ static void msw_FreeLegacyConsole() s_msw_console_allocated = false; + // clear C file handles to the console, otherwise FreeConsole() fails. + std::FILE* fp; + if (!s_msw_prev_stdin) + freopen_s(&fp, "NUL:", "w", stdin); + if (!s_msw_prev_stdout) + freopen_s(&fp, "NUL:", "w", stdout); + if (!s_msw_prev_stderr) + freopen_s(&fp, "NUL:", "w", stderr); + // restore previous handles prior to creating the console. ::SetStdHandle(STD_INPUT_HANDLE, s_msw_prev_stdin); ::SetStdHandle(STD_OUTPUT_HANDLE, s_msw_prev_stdout);