diff --git a/src/xenia/base/main_win.cc b/src/xenia/base/main_win.cc index c0c818bcc..a3a004445 100644 --- a/src/xenia/base/main_win.cc +++ b/src/xenia/base/main_win.cc @@ -124,6 +124,7 @@ int Main() { // Setup COM on the main thread. // NOTE: this may fail if COM has already been initialized - that's OK. +#pragma warning(suppress : 6031) CoInitializeEx(nullptr, COINIT_MULTITHREADED); // Initialize logging. Needs parsed FLAGS. diff --git a/src/xenia/kernel/xthread.cc b/src/xenia/kernel/xthread.cc index b5736db57..137c15d02 100644 --- a/src/xenia/kernel/xthread.cc +++ b/src/xenia/kernel/xthread.cc @@ -13,6 +13,10 @@ #include +#ifdef XE_PLATFORM_WIN32 +#include +#endif + #include "xenia/base/byte_stream.h" #include "xenia/base/clock.h" #include "xenia/base/logging.h" @@ -374,6 +378,20 @@ X_STATUS XThread::Create() { // Set name immediately, if we have one. thread_->set_name(thread_name_); +#ifdef XE_PLATFORM_WIN32 + // Setup COM on this thread. + // + // https://devblogs.microsoft.com/oldnewthing/?p=4613 + // + // "If any thread in the process calls CoInitialize[Ex] with the + // COINIT_MULTITHREADED flag, then that not only initializes the current + // thread as a member of the multi-threaded apartment, but it also says, + // "Any thread which has never called CoInitialize[Ex] is also part of the + // multi-threaded apartment." +#pragma warning(suppress : 6031) + CoInitializeEx(nullptr, COINIT_MULTITHREADED); +#endif + // Profiler needs to know about the thread. xe::Profiler::ThreadEnter(thread_name_.c_str());