mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
InputCommon: fix default input config default device not being loaded/found
Fixes bug: https://bugs.dolphin-emu.org/issues/12744
Before e1e3db13ba
the ControllerInterface m_devices_mutex was "wrongfully" locked for the whole Initialize() call, which included the first device population refresh,
this has the unwanted (accidental) consequence of often preventing the different pads (GC Pad, Wii Contollers, ...) input configs from loading
until that mutex was released (the input config defaults loading was blocked in EmulatedController::LoadDefaults()), which meant that the devices
population would often have the time to finish adding its first device, which would then be selected as default device (by design, the first device
added to the CI is the default default device, usually the "Keyboard and Mouse" device).
After the commit mentioned above removed the unnecessary m_devices_mutex calls, the default default device would fail to load (be found)
causing the default input mappings, which are specifically written for the default default device on every platform, to not be bound to any
physical device input, breaking input on new dolphin installations (until a user tried to customize the default device manually).
Default devices are now always added synchronously to avoid the problem, and so they should in the future (I added comments and warnings to help with that)
This commit is contained in:
@ -7,9 +7,9 @@
|
||||
|
||||
#include <array>
|
||||
#include <future>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include "Common/Event.h"
|
||||
#include "Common/Flag.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/ScopeGuard.h"
|
||||
@ -19,12 +19,12 @@
|
||||
|
||||
constexpr UINT WM_DOLPHIN_STOP = WM_USER;
|
||||
|
||||
static Common::Event s_received_device_change_event;
|
||||
// Dolphin's render window
|
||||
static HWND s_hwnd;
|
||||
// Windows messaging window (hidden)
|
||||
static HWND s_message_window;
|
||||
static std::thread s_thread;
|
||||
static std::mutex s_populate_mutex;
|
||||
static Common::Flag s_first_populate_devices_asked;
|
||||
|
||||
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
|
||||
@ -35,7 +35,7 @@ static LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wparam, LPARA
|
||||
// listen for it.
|
||||
if (s_first_populate_devices_asked.IsSet())
|
||||
{
|
||||
s_received_device_change_event.Set();
|
||||
std::lock_guard lk_population(s_populate_mutex);
|
||||
// TODO: we could easily use the message passed alongside this event, which tells
|
||||
// whether a device was added or removed, to avoid removing old, still connected, devices
|
||||
g_controller_interface.PlatformPopulateDevices([] {
|
||||
@ -135,14 +135,12 @@ void ciface::Win32::PopulateDevices(void* hwnd)
|
||||
if (s_thread.joinable())
|
||||
{
|
||||
s_hwnd = static_cast<HWND>(hwnd);
|
||||
// To avoid blocking this thread until the async population has finished, directly do it here
|
||||
// (we need the DInput Keyboard and Mouse "default" device to always be added without any wait).
|
||||
std::lock_guard lk_population(s_populate_mutex);
|
||||
s_first_populate_devices_asked.Set();
|
||||
s_received_device_change_event.Reset();
|
||||
// Do this forced devices refresh in the messaging thread so it won't cause any race conditions
|
||||
PostMessage(s_message_window, WM_INPUT_DEVICE_CHANGE, 0, 0);
|
||||
std::thread([] {
|
||||
if (!s_received_device_change_event.WaitFor(std::chrono::seconds(5)))
|
||||
ERROR_LOG_FMT(CONTROLLERINTERFACE, "win32 timed out when trying to populate devices");
|
||||
}).detach();
|
||||
ciface::DInput::PopulateDevices(s_hwnd);
|
||||
ciface::XInput::PopulateDevices();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -156,6 +154,7 @@ void ciface::Win32::ChangeWindow(void* hwnd)
|
||||
if (s_thread.joinable()) // "Has init?"
|
||||
{
|
||||
s_hwnd = static_cast<HWND>(hwnd);
|
||||
std::lock_guard lk_population(s_populate_mutex);
|
||||
ciface::DInput::ChangeWindow(s_hwnd);
|
||||
}
|
||||
}
|
||||
@ -168,7 +167,6 @@ void ciface::Win32::DeInit()
|
||||
PostMessage(s_message_window, WM_DOLPHIN_STOP, 0, 0);
|
||||
s_thread.join();
|
||||
s_message_window = nullptr;
|
||||
s_received_device_change_event.Reset();
|
||||
s_first_populate_devices_asked.Clear();
|
||||
DInput::DeInit();
|
||||
}
|
||||
|
Reference in New Issue
Block a user