Merge pull request #7969 from krzys-h/com-init-is-broken

Initialize COM only once, globally
This commit is contained in:
Twinaphex 2019-01-10 17:28:23 +01:00 committed by GitHub
commit 24ce1aee21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 38 deletions

View File

@ -589,7 +589,6 @@ static void *wasapi_init(const char *dev_id, unsigned rate, unsigned latency,
unsigned u1, unsigned *u2)
{
HRESULT hr;
bool com_initialized = false;
UINT32 frame_count = 0;
REFERENCE_TIME dev_period = 0;
BYTE *dest = NULL;
@ -601,11 +600,6 @@ static void *wasapi_init(const char *dev_id, unsigned rate, unsigned latency,
WASAPI_CHECK(w, "Out of memory", return NULL);
hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
WASAPI_HR_CHECK(hr, "CoInitializeEx", goto error);
com_initialized = true;
w->device = wasapi_init_device(dev_id);
if (!w->device && dev_id)
w->device = wasapi_init_device(NULL);
@ -685,8 +679,6 @@ error:
if (w->buffer)
fifo_free(w->buffer);
free(w);
if (com_initialized)
CoUninitialize();
return NULL;
}
@ -898,7 +890,6 @@ static void wasapi_free(void *wh)
_IAudioClient_Stop(w->client);
WASAPI_RELEASE(w->client);
WASAPI_RELEASE(w->device);
CoUninitialize();
if (w->buffer)
fifo_free(w->buffer);
free(w);

View File

@ -201,11 +201,6 @@ static xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels,
{
xaudio2_t *handle = NULL;
WAVEFORMATEX wfx = {0};
#if !defined(_XBOX) && !defined(__WINRT__)
HRESULT hr = CoInitialize(NULL);
if (FAILED(hr))
return NULL;
#endif
#if defined(__cplusplus) && !defined(CINTERFACE)
handle = new xaudio2;
@ -256,9 +251,6 @@ static xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels,
error:
xaudio2_free(handle);
#if !defined(_XBOX) && !defined(__WINRT__)
CoUninitialize();
#endif
return NULL;
}
@ -408,10 +400,6 @@ static void xa_free(void *data)
if (xa->xa)
xaudio2_free(xa->xa);
free(xa);
#if !defined(_XBOX) && !defined(__WINRT__)
CoUninitialize();
#endif
}
static size_t xa_write_avail(void *data)

View File

@ -46,6 +46,11 @@
#ifndef HAVE_MAIN
#include "../retroarch.h"
#include "../verbosity.h"
#if defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__)
#include <objbase.h>
#endif
#endif
/**
@ -109,6 +114,14 @@ int rarch_main(int argc, char *argv[], void *data)
const ui_application_t *ui_application = NULL;
#endif
#if !defined(HAVE_MAIN) && defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__)
if (FAILED(CoInitialize(NULL)))
{
RARCH_ERR("FATAL: Failed to initialize the COM interface\n");
return 1;
}
#endif
rarch_ctl(RARCH_CTL_PREINIT, NULL);
frontend_driver_init_first(args);
rarch_ctl(RARCH_CTL_INIT, NULL);
@ -157,6 +170,10 @@ int rarch_main(int argc, char *argv[], void *data)
ui_application->run(args);
#endif
#if !defined(HAVE_MAIN) && defined(_WIN32) && !defined(_XBOX) && !defined(__WINRT__)
CoUninitialize();
#endif
return 0;
}

View File

@ -83,12 +83,6 @@ static void* win32_display_server_init(void)
return NULL;
#ifdef HAS_TASKBAR_EXT
if (FAILED(CoInitialize(NULL)))
{
RARCH_ERR("COM initialization failed, ITaskbarList3 disabled\n");
return dispserv;
}
#ifdef __cplusplus
/* When compiling in C++ mode, GUIDs are references instead of pointers */
hr = CoCreateInstance(CLSID_TaskbarList, NULL,
@ -130,8 +124,6 @@ static void win32_display_server_destroy(void *data)
ITaskbarList3_Release(g_taskbarList);
g_taskbarList = NULL;
}
CoUninitialize();
#endif
if (dispserv)

View File

@ -98,8 +98,6 @@ void dinput_destroy_context(void)
IDirectInput8_Release(g_dinput_ctx);
g_dinput_ctx = NULL;
CoUninitialize();
}
bool dinput_init_context(void)
@ -107,12 +105,6 @@ bool dinput_init_context(void)
if (g_dinput_ctx)
return true;
if (FAILED(CoInitialize(NULL)))
{
RARCH_ERR("[DINPUT]: Failed to initialize the COM interface\n");
return false;
}
/* Who said we shouldn't have same call signature in a COM API? <_< */
#ifdef __cplusplus
if (!(SUCCEEDED(DirectInput8Create(
@ -131,7 +123,6 @@ bool dinput_init_context(void)
error:
RARCH_ERR("[DINPUT]: Failed to initialize DirectInput.\n");
CoUninitialize();
return false;
}