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
print()
output in console is garbled when using non-ASCII characters on Windows
#87591
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Did some digging but didn't find any immediate solution, unsure what's causing this quirk, probably something with how it handles redirection or wide characters |
You can fix the é by just doing SetConsoleOutputCP(CP_UTF8);
WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), buf, len, NULL, NULL); (no need for Could do a pull request, but I think @bruvzg is already on it? Edit: Oh, and I'm talking about |
SetConsoleOutputCP is a most obvious solution to the issue, but there might be issues with the way Godot is printing strings, and underlying CRT code (which is different in MinGW and MSVC), so it should be tested in various conditions. I have not done anything with it so far, just added to mt todo list. |
There's various prints that aren't necessarily going through the logger so has to be compatible with that, though those are largely crash related or extreme error cases with |
Okay, then I better leave that to someone more versed in the inner workings. In case it helps, here's how far I got: WindowsTerminalLogger::WindowsTerminalLogger() {
SetConsoleOutputCP(CP_UTF8);
}
void WindowsTerminalLogger::logv(const char *p_format, va_list p_list, bool p_err) {
if (!should_log(p_err)) {
return;
}
const unsigned int BUFFER_SIZE = 16384;
char buf[BUFFER_SIZE + 1]; // +1 for the terminating character
int len = vsnprintf(buf, BUFFER_SIZE, p_format, p_list);
if (len <= 0) {
return;
}
if ((unsigned int)len >= BUFFER_SIZE) {
len = BUFFER_SIZE; // Output is too big, will be truncated
}
buf[len] = 0;
WriteFile(GetStdHandle(p_err ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE), buf, len, NULL, NULL);
#ifdef DEBUG_ENABLED
FlushFileBuffers(GetStdHandle(p_err ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE));
#endif
} ( |
This works with the main executable, but not with a wrapper. But a bit more complex variant using both |
But unfortunately not working with redirects. |
I found this in the sources (godot/platform/windows/display_server_windows.cpp): Maybe the use of utf16 (more or less as often as utf8 in the Godot sources for Windows) could be the cause of the problem? |
Tested versions
System information
Windows 10 22H2
Issue description
Running the following code on Windows with the command prompt visible:
Results in:
Text appears correctly in the editor Output panel.
This occurs both from cmd.exe and PowerShell, both when using the standard executable and the console wrapper. I haven't tested Windows Terminal nor Windows 11 yet.
Steps to reproduce
Use
print()
or any derivatives with text that contains non-ASCII characters likeé
,×
,©
, and so on. Also try emoji for good measure:🙂
👋🏻
(note that only Windows Terminal can display those correctly, at least with colors)Minimal reproduction project (MRP)
test_unicode_print.zip
The text was updated successfully, but these errors were encountered: