diff --git a/Windows/DinputDevice.cpp b/Windows/DinputDevice.cpp index 4cd45f4bed..d92ffc8ac5 100644 --- a/Windows/DinputDevice.cpp +++ b/Windows/DinputDevice.cpp @@ -111,7 +111,9 @@ void DinputDevice::getDevices(bool refresh) { // We don't want duplicate reporting from XInput devices through DInput. ignoreDevices_ = DetectXInputVIDPIDs(); HidInputDevice::AddSupportedDevices(&ignoreDevices_); - getPDI()->EnumDevices(DI8DEVCLASS_GAMECTRL, &DinputDevice::DevicesCallback, NULL, DIEDFL_ATTACHEDONLY); + if (getPDI()) { + getPDI()->EnumDevices(DI8DEVCLASS_GAMECTRL, &DinputDevice::DevicesCallback, NULL, DIEDFL_ATTACHEDONLY); + } } } @@ -263,7 +265,7 @@ int DinputDevice::UpdateState() { DIJOYSTATE2 js{}; if (FAILED(pJoystick->Poll())) { - if(pJoystick->Acquire() == DIERR_INPUTLOST) + if (FAILED(pJoystick->Acquire())) return -1; } @@ -273,10 +275,6 @@ int DinputDevice::UpdateState() { ApplyButtons(js); if (analog) { - // TODO: Use the batched interface. - AxisInput axis; - axis.deviceId = DEVICE_ID_PAD_0 + pDevNum; - SendNativeAxis(DEVICE_ID_PAD_0 + pDevNum, js.lX, last_lX_, JOYSTICK_AXIS_X); SendNativeAxis(DEVICE_ID_PAD_0 + pDevNum, js.lY, last_lY_, JOYSTICK_AXIS_Y); SendNativeAxis(DEVICE_ID_PAD_0 + pDevNum, js.lZ, last_lZ_, JOYSTICK_AXIS_Z); @@ -300,7 +298,6 @@ int DinputDevice::UpdateState() { void DinputDevice::ApplyButtons(DIJOYSTATE2 &state) { const bool sendInput = g_Config.bAllowDInput; - BYTE *buttons = state.rgbButtons; u32 downMask = 0x80; for (int i = 0; i < ARRAY_SIZE(dinput_buttons); ++i) { @@ -393,7 +390,7 @@ static std::set DetectXInputVIDPIDs() { VARIANT var{}; if (SUCCEEDED(pDevices[i]->Get(L"DeviceID", 0, &var, nullptr, nullptr))) { - if (wcsstr(var.bstrVal, L"IG_")) + if (var.vt == VT_BSTR && var.bstrVal != nullptr && wcsstr(var.bstrVal, L"IG_")) { DWORD vid = 0, pid = 0; const WCHAR *strVid = wcsstr(var.bstrVal, L"VID_");