microsoft / microsoft/terminal
SetConsoleActiveScreenBuffer breaks Unicode output
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 105k
- Forks
- 9.6k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 29
Description
### Windows Terminal version
1.22.1972 and newer
### Windows build number
10.0.19045.4412
### Other Software
No
### Steps to reproduce
1. Compile this simple program:
```C++
#include
int main()
{
const auto Output = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD n;
WriteConsole(Output, L"𠜎𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎\n", 23, &n, {});
WriteConsole(Output, L"💖💫🐶🐇🌎🏃\n", 13, &n, {});
MessageBox({}, L"Press OK", {}, 0);
const auto NewBuffer = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, {}, CONSOLE_TEXTMODE_BUFFER, {});
SetConsoleActiveScreenBuffer(NewBuffer);
SetConsoleActiveScreenBuffer(Output);
MessageBox({}, L"See?", {}, 0);
}
```
2. Run it.
3. Follow the instructions.
### Expected Behavior
The text stays intact after pressing OK (and calling `SetConsoleActiveScreenBuffer(Output);`):

### Actual Behavior
The text is broken, as if a bad conversion happens somewhere:

#### Observations
- It stopped working somewhere between WT 1.22.1511.0 (1.22.240530001, 31 May) and 1.22.1972.0 (1.22.240715002, 17 Jul). Unfortunately I don't have any other versions in between.
- OpenConsole is not affected, only WT.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling and running the provided C++ reproduction on the affected Windows Terminal versions, comparing behavior with OpenConsole and the listed older version. Trace handling of SetConsoleActiveScreenBuffer and the transition back to the original buffer, then verify that the Unicode output remains intact after the second MessageBox is dismissed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- cli, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100