From a086501146bad002f1b6337b951dc84af75a63ce Mon Sep 17 00:00:00 2001 From: Piratux <58703216+Piratux@users.noreply.github.com> Date: Thu, 16 Mar 2023 23:21:10 +0200 Subject: [PATCH 1/2] ConsoleCaptureStdOut fix --- olcPixelGameEngine.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/olcPixelGameEngine.h b/olcPixelGameEngine.h index 92dee603..f961fb58 100644 --- a/olcPixelGameEngine.h +++ b/olcPixelGameEngine.h @@ -1248,6 +1248,7 @@ namespace olc // Command Console Specific bool bConsoleShow = false; bool bConsoleSuspendTime = false; + bool bConsoleCapturingStdOut = false; olc::Key keyConsoleExit = olc::Key::F1; std::stringstream ssConsoleOutput; std::streambuf* sbufOldCout = nullptr; @@ -3486,7 +3487,12 @@ namespace olc void PixelGameEngine::ConsoleCaptureStdOut(const bool bCapture) { - if(bCapture) + if (bConsoleCapturingStdOut == bCapture) + return; + + bConsoleCapturingStdOut = bCapture; + + if (bCapture) sbufOldCout = std::cout.rdbuf(ssConsoleOutput.rdbuf()); else std::cout.rdbuf(sbufOldCout); From e9a4e9518fd134291ce6a1d2326c5920494424cd Mon Sep 17 00:00:00 2001 From: Piratux <58703216+Piratux@users.noreply.github.com> Date: Fri, 17 Mar 2023 13:33:49 +0200 Subject: [PATCH 2/2] ConsoleCaptureStdOut additional fix --- olcPixelGameEngine.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/olcPixelGameEngine.h b/olcPixelGameEngine.h index f961fb58..0c4f02d6 100644 --- a/olcPixelGameEngine.h +++ b/olcPixelGameEngine.h @@ -1248,7 +1248,6 @@ namespace olc // Command Console Specific bool bConsoleShow = false; bool bConsoleSuspendTime = false; - bool bConsoleCapturingStdOut = false; olc::Key keyConsoleExit = olc::Key::F1; std::stringstream ssConsoleOutput; std::streambuf* sbufOldCout = nullptr; @@ -3487,10 +3486,11 @@ namespace olc void PixelGameEngine::ConsoleCaptureStdOut(const bool bCapture) { - if (bConsoleCapturingStdOut == bCapture) + if (ssConsoleOutput.rdbuf() == std::cout.rdbuf() && bCapture == true) return; - bConsoleCapturingStdOut = bCapture; + if (ssConsoleOutput.rdbuf() != std::cout.rdbuf() && bCapture == false) + return; if (bCapture) sbufOldCout = std::cout.rdbuf(ssConsoleOutput.rdbuf());