Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConsoleCaptureStdOut fix #330

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

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.

None yet

1 participant