Skip to content

Conversation

@Piratux
Copy link

@Piratux Piratux commented Mar 16, 2023

Currently, ConsoleCaptureStdOut function only works as expected when it's called once with each alternating argument and the first call to it having argument true:

ConsoleCaptureStdOut(true);
ConsoleCaptureStdOut(false);
ConsoleCaptureStdOut(true);
ConsoleCaptureStdOut(false);
...

However, it produces unexpected results when function gets called with false argument first:

ConsoleCaptureStdOut(false); // UNEXPECTED: std::cout redirected to nullptr

Or when there are 2+ consecutive calls with true argument:

ConsoleCaptureStdOut(true);
ConsoleCaptureStdOut(true);
ConsoleCaptureStdOut(false); // UNEXPECTED: std::cout still points to console output

This PR fixes both edge cases.

@Piratux
Copy link
Author

Piratux commented Mar 17, 2023

Fixed an additional edge case, where if user were to redirect std::cout, calling ConsoleCaptureStdOut(false) would redirect std::cout back to old location which may no longer be wanted:

ConsoleCaptureStdOut(true);
std::cout.rdbuf(nullptr);
ConsoleCaptureStdOut(false); // PROBABLY UNEXPECTED: std::cout could be redirected back to external console, even though std::cout was explicitly redirected in user's code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant