Log: Close C file handles on free (win32)

Fixes toggling console not hiding the window.
This commit is contained in:
Connor McLaughlin 2021-01-09 01:52:47 +10:00
parent 9951921a6d
commit 9d7f4523b0
1 changed files with 9 additions and 0 deletions

View File

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