From 9ec309eaa16c24818ef26ee83c5b7454a79b1f04 Mon Sep 17 00:00:00 2001 From: Souryo Date: Wed, 14 Dec 2016 20:49:41 -0500 Subject: [PATCH] DirectInput: Fixed bug that caused directinput to constantly scan for new devices --- Windows/DirectInputManager.cpp | 10 ++++++---- Windows/DirectInputManager.h | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Windows/DirectInputManager.cpp b/Windows/DirectInputManager.cpp index 1284ff30..c9f41b4d 100644 --- a/Windows/DirectInputManager.cpp +++ b/Windows/DirectInputManager.cpp @@ -38,8 +38,10 @@ bool DirectInputManager::Initialize() return UpdateDeviceList(); } -bool DirectInputManager::ProcessDevice(const GUID* deviceGuid, bool checkOnly) +bool DirectInputManager::ProcessDevice(const DIDEVICEINSTANCE* pdidInstance, bool checkOnly) { + const GUID* deviceGuid = &pdidInstance->guidInstance; + auto comp = [=](GUID guid) { return guid.Data1 == deviceGuid->Data1 && guid.Data2 == deviceGuid->Data2 && @@ -52,7 +54,7 @@ bool DirectInputManager::ProcessDevice(const GUID* deviceGuid, bool checkOnly) if(knownXInputDevice || knownDirectInputDevice) { return false; } else { - bool isXInput = IsXInputDevice(deviceGuid); + bool isXInput = IsXInputDevice(&pdidInstance->guidProduct); if(!checkOnly) { if(isXInput) { _xinputDeviceGuids.push_back(*deviceGuid); @@ -199,7 +201,7 @@ bool DirectInputManager::NeedToUpdate() int DirectInputManager::NeedToUpdateCallback(const DIDEVICEINSTANCE* pdidInstance, void* pContext) { - if(ProcessDevice(&pdidInstance->guidProduct, true)) { + if(ProcessDevice(pdidInstance, true)) { _needToUpdate = true; return DIENUM_STOP; } @@ -261,7 +263,7 @@ int DirectInputManager::EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstan { HRESULT hr; - if(ProcessDevice(&pdidInstance->guidInstance, false)) { + if(ProcessDevice(pdidInstance, false)) { // Obtain an interface to the enumerated joystick. LPDIRECTINPUTDEVICE8 pJoystick = nullptr; hr = _directInput->CreateDevice(pdidInstance->guidInstance, &pJoystick, nullptr); diff --git a/Windows/DirectInputManager.h b/Windows/DirectInputManager.h index 9f300ca7..d820ef66 100644 --- a/Windows/DirectInputManager.h +++ b/Windows/DirectInputManager.h @@ -22,7 +22,7 @@ private: bool Initialize(); bool UpdateInputState(DirectInputData& joystick); - static bool ProcessDevice(const GUID* deviceGuid, bool checkOnly); + static bool ProcessDevice(const DIDEVICEINSTANCE* pdidInstance, bool checkOnly); static bool IsXInputDevice(const GUID* pGuidProductFromDirectInput); static int __stdcall NeedToUpdateCallback(const DIDEVICEINSTANCE* pdidInstance, void* pContext); static int __stdcall EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, void* pContext);