usb_eyetoy: Clean up COM initialization, prevent a double-release
Some checks are pending
🐧 Linux Builds / AppImage (push) Waiting to run
🐧 Linux Builds / Flatpak (push) Waiting to run
🍎 MacOS Builds / Defaults (push) Waiting to run
🖥️ Windows Builds / Lint VS Project Files (push) Waiting to run
🖥️ Windows Builds / SSE4 (push) Blocked by required conditions
🖥️ Windows Builds / AVX2 (push) Blocked by required conditions
🖥️ Windows Builds / CMake (push) Waiting to run

If the EyeToy camera was enabled in the settings, but not enabled
by the game, it would call CoUninitialize without having called
CoInitializeEx first.
This commit is contained in:
Silent 2025-10-14 20:13:13 +02:00 committed by Ty
parent 521b32c253
commit 3cf21e0ab6
2 changed files with 11 additions and 3 deletions

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-3.0+
#include "common/Console.h"
#include "common/Error.h"
#include "common/StringUtil.h"
#include "videodev.h"
@ -527,7 +528,13 @@ namespace usb_eyetoy
int DirectShow::Open(int width, int height, FrameFormat format, int mirror)
{
dshowCoInitialize = wil::CoInitializeEx_failfast(COINIT_MULTITHREADED);
const HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (FAILED(hr))
{
Console.ErrorFmt("CoInitializeEx failed: {}", Error::CreateHResult(hr).GetDescription());
return -1;
}
wil::unique_couninitialize_call uninit;
frame_width = width;
frame_height = height;
@ -545,7 +552,7 @@ namespace usb_eyetoy
int ret = InitializeDevice(StringUtil::UTF8StringToWideString(mHostDevice));
if (ret < 0)
{
Console.Warning("Camera: cannot find '%s'", mHostDevice.c_str());
Console.WarningFmt("Camera: cannot find '{}'", mHostDevice);
return -1;
}
@ -559,6 +566,7 @@ namespace usb_eyetoy
return -1;
}
dshowCoInitialize = std::move(uninit);
return 0;
};

View File

@ -83,7 +83,7 @@ namespace usb_eyetoy
int InitializeDevice(const std::wstring& selectedDevice);
private:
wil::unique_couninitialize_call dshowCoInitialize;
wil::unique_couninitialize_call dshowCoInitialize{false};
ICaptureGraphBuilder2* pGraphBuilder;
IFilterGraph2* pGraph;
IMediaControl* pControl;