From 4effa999b31f6c7e21469bbf89de76fe8bc3cd02 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 28 Nov 2021 21:33:46 +0100 Subject: [PATCH] debug: Fixed application crashing on Windows if not console is attached --- source/window/win_window.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/source/window/win_window.cpp b/source/window/win_window.cpp index f757018cf..35e7d9c50 100644 --- a/source/window/win_window.cpp +++ b/source/window/win_window.cpp @@ -171,17 +171,19 @@ void Window::initNative() { // Attach to parent console if one exists - AttachConsole(ATTACH_PARENT_PROCESS); + if (AttachConsole(ATTACH_PARENT_PROCESS)) { - // Redirect cin, cout and cerr to that console - freopen("CONIN$", "w", stdin); - freopen("CONOUT$", "w", stdout); - freopen("CONERR$", "w", stderr); - setvbuf(stdin, nullptr, _IONBF, 0); - setvbuf(stdout, nullptr, _IONBF, 0); - setvbuf(stderr, nullptr, _IONBF, 0); + // Redirect cin, cout and cerr to that console + freopen("CONIN$", "w", stdin); + freopen("CONOUT$", "w", stdout); + freopen("CONERR$", "w", stderr); + setvbuf(stdin, nullptr, _IONBF, 0); + setvbuf(stdout, nullptr, _IONBF, 0); + setvbuf(stderr, nullptr, _IONBF, 0); + + fmt::print("\n"); + } - fmt::print("\n"); // Enable color format specifiers in console {