libobs: Robust COM initialization

Qt seems to force STA, so it's misleading to ask for MTA and ignore the
failure result, so just ask for STA. Also, don't uninitialize COM if
initialization failed.
This commit is contained in:
jpark37 2019-11-24 09:46:41 -08:00
parent 7d3e086e6f
commit 66d78275e2
2 changed files with 13 additions and 5 deletions

View File

@ -1259,9 +1259,15 @@ void obs_init_win32_crash_handler(void)
initialize_crash_handler();
}
void initialize_com(void)
bool initialize_com(void)
{
CoInitializeEx(0, COINIT_MULTITHREADED);
const HRESULT hr = CoInitializeEx(0, COINIT_APARTMENTTHREADED);
const bool success = SUCCEEDED(hr);
if (success)
blog(LOG_INFO, "CoInitializeEx succeeded: 0x%08X", hr);
else
blog(LOG_ERROR, "CoInitializeEx failed: 0x%08X", hr);
return success;
}
void uninitialize_com(void)

View File

@ -871,8 +871,9 @@ static bool obs_init(const char *locale, const char *module_config_path,
}
#ifdef _WIN32
extern void initialize_com(void);
extern bool initialize_com(void);
extern void uninitialize_com(void);
static bool com_initialized = false;
#endif
/* Separate from actual context initialization
@ -933,7 +934,7 @@ bool obs_startup(const char *locale, const char *module_config_path,
}
#ifdef _WIN32
initialize_com();
com_initialized = initialize_com();
#endif
success = obs_init(locale, module_config_path, store);
@ -1048,7 +1049,8 @@ void obs_shutdown(void)
bfree(cmdline_args.argv);
#ifdef _WIN32
uninitialize_com();
if (com_initialized)
uninitialize_com();
#endif
}