diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp index eabc2cd0f1..1d198ca494 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.cpp @@ -140,6 +140,19 @@ void ControllerInterface::RefreshDevices() InvokeDevicesChangedCallbacks(); } +void ControllerInterface::PlatformPopulateDevices(std::function callback) +{ + if (!m_is_init) + return; + + m_is_populating_devices = true; + + callback(); + + m_is_populating_devices = false; + InvokeDevicesChangedCallbacks(); +} + // Remove all devices and call library cleanup functions void ControllerInterface::Shutdown() { diff --git a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h index 4f1651f361..84209a720b 100644 --- a/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h +++ b/Source/Core/InputCommon/ControllerInterface/ControllerInterface.h @@ -50,6 +50,7 @@ public: void Shutdown(); void AddDevice(std::shared_ptr device); void RemoveDevice(std::function callback); + void PlatformPopulateDevices(std::function callback); bool IsInit() const { return m_is_init; } void UpdateInput(); diff --git a/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp b/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp index 67a31a062a..096ad31827 100644 --- a/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Win32/Win32.cpp @@ -28,8 +28,10 @@ static LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARA { if (message == WM_INPUT_DEVICE_CHANGE) { - ciface::DInput::PopulateDevices(s_hwnd); - ciface::XInput::PopulateDevices(); + g_controller_interface.PlatformPopulateDevices([] { + ciface::DInput::PopulateDevices(s_hwnd); + ciface::XInput::PopulateDevices(); + }); s_done_populating.Set(); }