Gamepad stops working after reconnecting
brukwa opened this issue ยท 6 comments
Problem
Gamepad class stops working after specific sequence of events.
Moreover it can cause crash on calling it's destructor. Now hold on... after application is restarted gamepad still does not work until dmw.exe process is restarted! ๐จ
Environment
OS: Windows 10 21H2 (OS Build 19044.2075)
Controller: Xbox Series S/X Controller or Xbox One Controller (tested on both) connected with usb cable
DirectXTK: https://github.com/microsoft/DirectXTK/releases/tag/jul2022
Experiment: Preparation
I have created simplest Win32 application and changed the main loop to include some traces
MSG msg;
// Create GamePad instance
auto pGamepad = std::make_unique<DirectX::GamePad>();
// Main message loop:
do
{
// Pump some messages
while (TRUE == ::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
return 0;
}
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
// Read Gamepad current state and trace to outpu info that 'A' button has been pressed
auto state = pGamepad->GetState(0);
if (state.buttons.a)
{
::OutputDebugStringA("Pressed\n");
}
}
while (true);
I have also included a simple trace to Gamepad::OnGameInputDevice
std::string trace = "Callback " + std::to_string(currentStatus) + "\n";
OutputDebugStringA(trace.c_str());
Experiment: Execution
- Start the application with one controller connected
It is traced as connected:Callback 7
: โ - Disconnect controller
It is traced as disconnected:Callback 0
: โ
โน This is just a control check to see that the disconnection event is reported
- Reconnect controller
It is traced as connected:Callback 7
: โ - Press 'A' button
It is traced as pressed event a few times:Pressed
: โ - Disconnect controller
There is no disconnection event reported: โ - Reconnect controller
There is no connection event reported: โ - Press 'A' button
There is no button press event reported: โ
Now to make things even worse
- Restart the whole application with controller connected
There is a stream of traces reporting connection and disconnection of a controller that goes on and on โ
- Press 'A' button
There is no button press event reported: โ - Close main window (graceful shutdown)
Application crashes and the Access Violation error is reported โ
Callstack:
โ I have to close the dwm.exe
process to make the application report controller events.
๐จ
I think this might be a problem with dmw.exe or GameInput library from GDK, but I have no idea how to diagnose it.
What can I do to find the source of this problem?
Which version of the Microsoft GDK are you using?
June 2022 Update 2 (220602). Currently it is the latest one.
https://github.com/microsoft/GDK/releases/tag/June_2022_Update_2
I have noticed one more weird thing, trying to get input using Game Input API from GDK.
Code below gets current gamepad input readings
ComPtr<IGameInputReading> pReading;
HRESULT hr = m_pInput->GetCurrentReading(GameInputKindGamepad, nullptr, &pReading);
- Disonnect gamepad and the
hr
equalsGAMEINPUT_E_READING_NOT_FOUND
. Fine. - Connect gamepad and the
hr
equalsS_OK
. Fine - Press some buttons and disconnect Gamepad. The
hr
is stillS_OK
instead ofGAMEINPUT_E_READING_NOT_FOUND
.
Moreover, after restarting whole application it is stillS_OK
for disconnected gamepad untill dwm.exe process is restarted.
It seems like Game Input has some problems with handling gamepad disconnections.
Is there anything I can do to help in diagnosing this ... issue?
Can you try out the October 2022 release from https://github.com/microsoft/GDK/tree/2210_OCTOBER
Almost good news. I did manage to install 'June 2022 Update 4 Public Release' (https://github.com/microsoft/GDK/releases/tag/June_2022_Update_4) and the problem seems to be gone.
I am not able to install the October update :(
I get an error and I do not how to install this from git repository.
Unable to verify integrity of downloaded content. It might be corrupted. Please check your network connection and try again.
I think we can close this issue, since it is a problem with GDK.
BTW do you have any hint how to install October version from git repository?