From c1f9bd293133eb46e94c0be63bf256e6a0b32b42 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Tue, 27 Jan 2026 00:28:49 +0000 Subject: [PATCH 1/3] Fix DebugOutput https://gitlab.com/OpenMW/openmw/-/issues/8944 --- components/debug/debugging.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/components/debug/debugging.cpp b/components/debug/debugging.cpp index 6a6f044eee..9ada024431 100644 --- a/components/debug/debugging.cpp +++ b/components/debug/debugging.cpp @@ -173,10 +173,7 @@ namespace Debug return All; } - virtual std::streamsize writeImpl(const char* str, std::streamsize size, Level debugLevel) - { - return size; - } + virtual std::streamsize writeImpl(const char* str, std::streamsize size, Level debugLevel) { return size; } }; #if defined _WIN32 && defined _DEBUG @@ -185,10 +182,16 @@ namespace Debug public: std::streamsize writeImpl(const char* str, std::streamsize size, Level debugLevel) { - // Make a copy for null termination - std::string tmp(str, static_cast(size)); + if (size > std::numeric_limits::max()) + OutputDebugStringW(L"Next line truncated..."); + auto wideSize = MultiByteToWideChar(CP_UTF8, 0, str, + static_cast(std::min(size, std::numeric_limits::max())), nullptr, 0); + std::wstring wide(wideSize, L'\0'); + MultiByteToWideChar(CP_UTF8, 0, str, + static_cast(std::min(size, std::numeric_limits::max())), wide.data(), + wideSize); // Write string to Visual Studio Debug output - OutputDebugString(tmp.c_str()); + OutputDebugStringW(wide.c_str()); return size; } From 0520928a67f2a4facf3cf63bce8d4e24e999f2ef Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Tue, 27 Jan 2026 00:32:03 +0000 Subject: [PATCH 2/3] Undo something clang-format did because clang-format doesn't like it --- components/debug/debugging.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/debug/debugging.cpp b/components/debug/debugging.cpp index 9ada024431..914d2e457f 100644 --- a/components/debug/debugging.cpp +++ b/components/debug/debugging.cpp @@ -173,7 +173,10 @@ namespace Debug return All; } - virtual std::streamsize writeImpl(const char* str, std::streamsize size, Level debugLevel) { return size; } + virtual std::streamsize writeImpl(const char* str, std::streamsize size, Level debugLevel) + { + return size; + } }; #if defined _WIN32 && defined _DEBUG From c2069f518646656d4f37363bb7a19764d7fc74b2 Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Tue, 27 Jan 2026 14:31:31 +0000 Subject: [PATCH 3/3] Fix stdout/stderr, too. Although Windows as a whole got support for CP_UTF8 after Windows 10 (so some Enterprise IoT builds are non-EoL and don't support it for some functions), using it for SetConsoleOutputCP has been allowed since Windows 8, which is older than we support. --- components/debug/debugging.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/components/debug/debugging.cpp b/components/debug/debugging.cpp index 914d2e457f..ff0404f0d5 100644 --- a/components/debug/debugging.cpp +++ b/components/debug/debugging.cpp @@ -432,6 +432,7 @@ namespace Debug { #if defined _WIN32 (void)attachParentConsole(); + SetConsoleOutputCP(CP_UTF8); #endif rawStdout = std::make_unique(std::cout.rdbuf()); rawStderr = std::make_unique(std::cerr.rdbuf());