Skip to content

Commit

Permalink
Add some more safeguards to be sure
Browse files Browse the repository at this point in the history
  • Loading branch information
Pär Björklund committed Sep 30, 2016
1 parent 865d87b commit 2e0c6fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/api/directinput/JoystickDirectInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ CJoystickDirectInput::CJoystickDirectInput(GUID device

CJoystickDirectInput::~CJoystickDirectInput()
{
if (m_joystickDevice)
m_joystickDevice->Unacquire();

SAFE_RELEASE(m_joystickDevice);
}

Expand Down
10 changes: 10 additions & 0 deletions src/api/directinput/JoystickInterfaceDirectInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down

0 comments on commit 2e0c6fa

Please sign in to comment.