UI: Convert to wide before outputting debug text (win)

Fixes an issue where non-english debug text wouldn't display correctly
in the debugger output on windows.  Also, only output debug text when
actually debugging.

Closes jp9000/obs-studio#734
This commit is contained in:
Lionheart Zhang 2016-12-24 03:08:22 +08:00 committed by jp9000
parent 1d5a5558ab
commit 9050febf06

View file

@ -20,6 +20,7 @@
#include <wchar.h>
#include <chrono>
#include <ratio>
#include <string>
#include <sstream>
#include <mutex>
#include <util/bmem.h>
@ -316,8 +317,19 @@ static void do_log(int log_level, const char *msg, va_list args, void *param)
vsnprintf(str, 4095, msg, args);
#ifdef _WIN32
OutputDebugStringA(str);
OutputDebugStringA("\n");
if (IsDebuggerPresent()) {
static wstring wide_buf;
int wNum = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
if (wNum > 1) {
wide_buf.reserve(wNum + 1);
wide_buf.resize(wNum - 1);
MultiByteToWideChar(CP_UTF8, 0, str, -1, &wide_buf[0],
wNum);
wide_buf.push_back('\n');
OutputDebugStringW(wide_buf.c_str());
}
}
#else
def_log_handler(log_level, msg, args2, nullptr);
#endif