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

WriteConsoleOutput() with 0s produces undefined results instead of clearing like on previous versions #14441

Closed
Jimbly opened this issue Nov 25, 2022 · 5 comments
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@Jimbly
Copy link

Jimbly commented Nov 25, 2022

Windows Terminal version

1.15.2875.0

Windows build number

10.0.22621.819

Other Software

No response

Steps to reproduce

Run a legacy console app that uses WriteConsoleOutput to clear portions of the screen, instead of clearing, results are undefined / timing-dependent and never correct.

Example program:

#include <Windows.h>
#include <stdio.h>

// Expected output:
///  If you can see      there is a bug
// Actual output:
///  If you can see THIS there is a bug
// Output without Sleep():
///  If you can see  there is a bug
int main() {
	HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
	CHAR_INFO blank[4] = { 0 };
	// Workaround if you have access to the original code:
	// 	for (int ii = 0; ii < 4; ii++) {
	// 		blank[ii].Char.AsciiChar = ' ';
	// 	}
	printf("\nIf you can see THIS there is a bug\r");
	Sleep(100); // Without this, the bug is even weirder

	CONSOLE_SCREEN_BUFFER_INFO csbiInfo2;
	GetConsoleScreenBufferInfo(hConsoleOut, &csbiInfo2);
	COORD pos = csbiInfo2.dwCursorPosition;
	SHORT X = pos.X + sizeof("If you can see");
	SMALL_RECT region = { X, pos.Y, csbiInfo2.dwSize.X - 1, pos.Y };
	WriteConsoleOutput(hConsoleOut, blank, { 4, 1 }, { 0, 0 }, &region);
	printf("\n");
}

Expected Behavior

No response

Actual Behavior

Either nothing is written to the screen, or the characters to be overwritten are instead removed from the terminal buffer and everything else shifted over.

@Jimbly Jimbly added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Nov 25, 2022
@Jimbly Jimbly changed the title On Windows 11, WriteConsoleOutput() with 0s produces undefined results instead of clearing on previous versions On Windows 11, WriteConsoleOutput() with 0s produces undefined results instead of clearing like on previous versions Nov 25, 2022
@j4james
Copy link
Collaborator

j4james commented Nov 25, 2022

When you say "On Windows 11", do you just mean when using Windows Terminal, which is now the default terminal for Windows 11?

The reason I ask is because this sounds like #6265 (also #4363), which has always been a problem on Windows Terminal. However, if you switch the default terminal back to the old console, your test case should still work, even on Windows 11.

@Jimbly
Copy link
Author

Jimbly commented Nov 26, 2022

Sorry, I do not know exactly where the problem lies, just that it is a problem on Windows 11, and does not happen on Windows 10.

Ah, I found just now how to change the default terminal. OMG, so much better, all of my old apps are working again =). Yes, this appears to be only an issue with Windows Terminal, and this looks similar to those linked issues (although the fact that it behaves different depending on timing might mean this is something different - not just the wrong characters making it through, but something going wrong while buffering somewhere).

@Jimbly Jimbly changed the title On Windows 11, WriteConsoleOutput() with 0s produces undefined results instead of clearing like on previous versions WriteConsoleOutput() with 0s produces undefined results instead of clearing like on previous versions Nov 26, 2022
@PankajBhojwani
Copy link
Contributor

/dup #6265 #4363

@ghost
Copy link

ghost commented Nov 30, 2022

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost ghost closed this as completed Nov 30, 2022
@ghost ghost added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Nov 30, 2022
@PankajBhojwani
Copy link
Contributor

Thank you for reporting this! We are tracking this over at #6265 and #4363, but don't have a good answer for it yet. If you'd like to see our progress on this, those linked issues would be a good place to check :)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

3 participants