From 2e0c6fa758f8d2a3fe341f6d9ad23cfa0f1fe1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A4r=20Bj=C3=B6rklund?= Date: Fri, 30 Sep 2016 16:41:58 +0200 Subject: [PATCH] Add some more safeguards to be sure --- src/api/directinput/JoystickDirectInput.cpp | 3 +++ src/api/directinput/JoystickInterfaceDirectInput.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/api/directinput/JoystickDirectInput.cpp b/src/api/directinput/JoystickDirectInput.cpp index 2e0a3b7e..44eef79c 100644 --- a/src/api/directinput/JoystickDirectInput.cpp +++ b/src/api/directinput/JoystickDirectInput.cpp @@ -47,6 +47,9 @@ CJoystickDirectInput::CJoystickDirectInput(GUID device CJoystickDirectInput::~CJoystickDirectInput() { + if (m_joystickDevice) + m_joystickDevice->Unacquire(); + SAFE_RELEASE(m_joystickDevice); } diff --git a/src/api/directinput/JoystickInterfaceDirectInput.cpp b/src/api/directinput/JoystickInterfaceDirectInput.cpp index 793ae648..fb136842 100644 --- a/src/api/directinput/JoystickInterfaceDirectInput.cpp +++ b/src/api/directinput/JoystickInterfaceDirectInput.cpp @@ -142,6 +142,16 @@ BOOL CALLBACK CJoystickInterfaceDirectInput::EnumJoysticksCallback(const DIDEVIC return DIENUM_CONTINUE; } + // This will be done automatically when we're in the foreground but + // let's do it here to check that we can acquire it and that no other + // app has it in exclusive mode + hr = pJoystick->Acquire(); + if (FAILED(hr)) + { + esyslog("%s: Failed to acquire device on: %s", __FUNCTION__, pdidInstance->tszProductName); + return DIENUM_CONTINUE; + } + const std::string strName = pdidInstance->tszProductName ? pdidInstance->tszProductName : ""; context->AddScanResult(JoystickPtr(new CJoystickDirectInput(pdidInstance->guidInstance, pJoystick, strName)));