microsoft/DirectXTK

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

  1. Start the application with one controller connected
    It is traced as connected: Callback 7: โœ”
  2. Disconnect controller
    It is traced as disconnected: Callback 0: โœ”

โ„น This is just a control check to see that the disconnection event is reported

  1. Reconnect controller
    It is traced as connected: Callback 7: โœ”
  2. Press 'A' button
    It is traced as pressed event a few times: Pressed : โœ”
  3. Disconnect controller
    There is no disconnection event reported: โŒ
  4. Reconnect controller
    There is no connection event reported: โŒ
  5. Press 'A' button
    There is no button press event reported: โŒ

Now to make things even worse

  1. 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 โŒ
    image
  2. Press 'A' button
    There is no button press event reported: โŒ
  3. Close main window (graceful shutdown)
    Application crashes and the Access Violation error is reported โŒ
    image
    Callstack:
    image

โš  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);
  1. Disonnect gamepad and the hr equals GAMEINPUT_E_READING_NOT_FOUND. Fine.
  2. Connect gamepad and the hr equals S_OK. Fine
  3. Press some buttons and disconnect Gamepad. The hr is still S_OK instead of GAMEINPUT_E_READING_NOT_FOUND.
    Moreover, after restarting whole application it is still S_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.

image

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?

Sorry, I should've mentioned that the GDK repository uses git-lfs.

In any case, sounds like it's fixed in newer GDK builds which is great.