microsoft / microsoft/terminal

SetConsoleActiveScreenBuffer breaks Unicode output

Open
#17,580 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Bug Needs-Tag-Fix Priority-3 Product-Conpty
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);`):

![image](https://github.com/user-attachments/assets/474ca7a0-f487-4e5d-94b2-339d39eaa5ce)

### Actual Behavior

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

![image](https://github.com/user-attachments/assets/3a6a8e41-29a1-4f69-85a7-a2f39bef56ad)

#### 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.