diff --git a/src/dawn/common/Log.cpp b/src/dawn/common/Log.cpp index 265d156bff..c7a180b2ff 100644 --- a/src/dawn/common/Log.cpp +++ b/src/dawn/common/Log.cpp @@ -23,6 +23,9 @@ #if DAWN_PLATFORM_IS(ANDROID) #include #endif +#if DAWN_PLATFORM_IS(WINDOWS) +#include +#endif namespace dawn { @@ -99,6 +102,20 @@ LogMessage::~LogMessage() { outputStream = stderr; } +#if DAWN_PLATFORM_IS(WINDOWS) && defined(OFFICIAL_BUILD) + // If we are in a sandboxed process on an official build, the stdout/stderr + // handles are likely not set, so trying to log to them will crash. + HANDLE handle; + if (outputStream == stderr) { + handle = GetStdHandle(STD_ERROR_HANDLE); + } else { + handle = GetStdHandle(STD_OUTPUT_HANDLE); + } + if (handle == INVALID_HANDLE_VALUE) { + return; + } +#endif // DAWN_PLATFORM_IS(WINDOWS) && defined(OFFICIAL_BUILD) + // Note: we use fprintf because includes static initializers. fprintf(outputStream, "%s: %s\n", severityName, fullMessage.c_str()); fflush(outputStream);