-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Malformed/Partially destroyed Standard output from Visual studio (& others) #14512
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
Comments
I could have sworn there was s dupe for this somewhere on the backlog... Part of me worries that this is defterm specific. Like, the issue wouldn't repro in the Terminal if you launched the sample exe as Does selecting the missing output with the mouse cause it to reappear/? If so, this could be #11214 |
No, it does not. I can even select and copy paste everything and the text corresponds to what is visible in the terminal. In case it has any significance, I did not find a way to reproduce the issue by running the program directly from the terminal (without setting it as default terminal and running it from VS). |
This is pretty strange, and I can't reproduce it on VS 17.4.0. Can you share your |
I figured it may be easier to reproduce if I just reset the settings to default (I erased everything in the settings.json and restarted the terminal). I am still able to reproduce the issue even with default settings. I any case here is my current settings.json: There is another little detail I have noticed: the scrollbar behaves pretty weird. Before I start scrolling, it is pretty large, as soon as I start scrolling, it gets way smaller: Before scrolling: When I start scrolling:
That is strange, keep in mind it is (usually) necessary to repeat the process (closing terminal and start without debuggin) several times. I have tried reproducing it in a VM, but I could not, although I have a feeling a reason could be the VM is very slow so the text is printed without being buffered or whatever magic is going on behind the scenes. Edit: Also if I add a little delay (some heavy computation) before the program starts printing, the issue does not occur. Is it possible the terminal is not "initialized" yet? |
I can confirm, that I get exactly the same bug. First I thought it had to do with the 17.5 Preview version of Visual Studio. But even after rolling back from preview, the bug persisted. I first experienced this bug a few days back. But in that case there was no scrolling involved. Just missing pieces of console output. Like the "Press any key to close this window..." was only displayed as "Press any" and then nothing. But also text in the middle of several outputs was just missing. As I said I fist suspected a bug in Visual Studio, as sometimes the issue could be resolved by switching from debug to release, but then again, this only sometimes worked. I can reproduce this bug in C# and C++, it doesn't matter. As has already been stated, a small delay or a Console.Clear() at the beginning solve the issue. As an example, using As you can see, in this case some output to the right is just missing. It's not wrapped, but missing. |
Not sure if this helps, but I found that if you leave the terminal window open and then just run the code again, without closing terminal window first, the issue doesn't appear. I can reproduce this all the time; first run = bugs, second run without closing terminal first = no issue. |
But what really puzzles me is the fact, that I have been experiencing this issue first time a few weeks ago. So it could correspond with the release of v1.15.3466.0 2 weeks ago, but going back to v1.15.2875 doesn't solve the issue. PS: Happy new year to everyone 😁 |
You know what, we play all sorts of silly games on "the first paint" for conpty. I bet there's something fucky going on there with outputting more than a whole screen full of text before ConPTY does it's first frame. I've been out of the codebase for two weeks, but that's where I'd starts. #14547 has basically the same repro and side effects. I bet they're the same. |
This comment was marked as outdated.
This comment was marked as outdated.
Uhg. I just needed to try more. This must be some strange race, cause I just got this in the current main (4c7879b). How are we gonna debug this? This is intermittent, timing-based, and occurs via defterm. Defterm means we can't use the debug tap. I'd reckon that attaching to VS would probably break the repro. My assumption from before is where I think I'll start:
We've got two sets of symptoms here: |
I put a test in |
Scheduled for 1.18 I guess, still no fix. At least it's easy to work around, but it's ugly. |
This is a theory. I want to audit the uses of `CONSOLE_INFORMATION::IsInVtIoMode` before I commit to this. But I think this: * fixes #15245 * fixes #14512 Because basically, we'd create the first screen buffer with 9001 rows, because it would be created _before_ VtIo would be in a state to say "yes, we're a conpty"
I think this is fixed in #15298. I want to check that in to 1.18 and actually verify that this issue is resolved in 1.18, before committing that it closes this thread. |
We need to act like a ConPTY just a little earlier in startup. My relevant notes start here: #15245 (comment). Basically, we'd create the first screen buffer with 9001 rows, because it would be created _before_ VtIo would be in a state to say "yes, we're a conpty". Then, if a CLI app emits an entire screenful of text _before_ the terminal has a chance to resize the conpty, then the conpty will explode during `_DoLineFeed`. That method is absolutely not expecting the buffer to get resized (and the old text buffer deallocated). Instead, this will treat the console as in ConPty mode as soon as `VtIo::Initialize` is called (this is during `ConsoleCreateIoThread`, which is right at the end of `ConsoleEstablishHandoff`, which is before the API server starts to process the client connect message). THEORETICALLY, `VtIo` could `Initialize` then fail to create objects in `CreateIoHandlers` (which is what we used to treat as the moment that we were in conpty mode). However, if we do fail out of `CreateIoHandlers`, then the console itself will fail to start up, and just die. So I don't think that's needed. This fixes #15245. I think this is PROBABLY also the solution to #14512, but I'm not gonna explicitly mark closed. We'll loop back on it.
v1.18.1421.0 fixes the issue for me. |
I'm running Visual Studio Community 17.6.2 and I'm getting the same bug. Anything I can add to my code besides Running without Debugging twice to stitch the issue? |
Why not update the Terminal? You can add a small delay, that's what I did to work around it. Like 50-60 ms or so before you start printing. Or you can switch to the Windows Console. |
@whshields which Terminal version are you using? This is totally just a bug in the Terminal, regardless of VS version. I'm really tempted to just close this out now. We seemingly haven't gotten any reports of this in the last month, and it was a pretty noisy bug before that. |
In case it has any weight, I am still able to reproduce the bug even using the latest (stable) versions (Terminal 1.17.11461.0; VS 17.6.4), but I have noticed it is not consistently reproducible (that said in my case the output is destroyed in almost 100 % of cases), probably depends on a machine's performance if not other factors. |
That would make sense - the PR I think fixed this (#15298) is only in 1.18 (Preview) builds currently. |
@zadjii-msft I have tried the preview version, the issue seems to be fixed, well done! So, at least from my side this issue can be closed, if that's ok with you. |
Fixed in v1.18. |
We need to act like a ConPTY just a little earlier in startup. My relevant notes start here: #15245 (comment). Basically, we'd create the first screen buffer with 9001 rows, because it would be created _before_ VtIo would be in a state to say "yes, we're a conpty". Then, if a CLI app emits an entire screenful of text _before_ the terminal has a chance to resize the conpty, then the conpty will explode during `_DoLineFeed`. That method is absolutely not expecting the buffer to get resized (and the old text buffer deallocated). Instead, this will treat the console as in ConPty mode as soon as `VtIo::Initialize` is called (this is during `ConsoleCreateIoThread`, which is right at the end of `ConsoleEstablishHandoff`, which is before the API server starts to process the client connect message). THEORETICALLY, `VtIo` could `Initialize` then fail to create objects in `CreateIoHandlers` (which is what we used to treat as the moment that we were in conpty mode). However, if we do fail out of `CreateIoHandlers`, then the console itself will fail to start up, and just die. So I don't think that's needed. This fixes #15245. I think this is PROBABLY also the solution to #14512, but I'm not gonna explicitly mark closed. We'll loop back on it. (cherry picked from commit 6ad8cd0) Service-Card-Id: 89112504 Service-Version: 1.17
Windows Terminal version
1.15.2875.0
Windows build number
10.0.22000.1281
Other Software
Microsoft Visual Studio Community 2022 (64-bit) - Current
Version 17.4.2
Steps to reproduce
Expected Behavior
I would expect to see previous output lines correctly when I scroll up.
Actual Behavior
There is no output above the previously visible text, or the output is malformed.

Note: Classic console works as expected in this scenario.
The text was updated successfully, but these errors were encountered: