gamepads icon indicating copy to clipboard operation
gamepads copied to clipboard

Windows: App infinite loop and crash occurs after disconnecting non-gamepad USB device.

Open joshhammock opened this issue 8 months ago • 4 comments

First off, the recent work on gamepads is much appreciated and has been perfect for my current project. Thank you!

There is an issue that I'm able to consistently recreate when unplugging a non-gamepad usb device from my windows PC. It's not every time, but often the first or second time. The devices that I've tried with were a usb hub, keyboard, and mouse.

The loop appears to be in GamepadListenerProc and it's repeatedly calling update_gamepads and seems to be alternating wParam between DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE.

That's about as far as my knowledge goes, but it might just need something to detect and prevent starting the listener if the device is not a gamepad.

joshhammock avatar May 01 '25 21:05 joshhammock

+1

wantroba avatar Jun 18 '25 17:06 wantroba

+1

miguelsotobaez avatar Sep 08 '25 13:09 miguelsotobaez

I have a potentially related issue when I re-connect my wireless gamepad, that the update loop freezes.

When I have debugged it I have noticed that I get updates due to name changing from "MS-drivrutin för PC-spelenhet" to empty string "". When I look on it further, I am unsure what the purpose of this name change update is. I first thought it was if the gamepad is changed, but we have the outer device handling for that. So maybe it is to update the name sent to Dart/Flutter side. ~~But then it might be better to use std::atomic to pass it to the other thread than stopping/restarting the thread. ~~

Edit: realized that that idea won't work. So the thread restart is likely there to facilitate the name update.

lea108 avatar Oct 09 '25 20:10 lea108

Perhaps you could try if https://github.com/flame-engine/gamepads/pull/81 helps with this issue? If not, it is valuable feedback on that PR.

For me, it fixes the issues that I had with crashes when my gamepad disconnects.

Note that it does have breaking changes on the input mapping.

lea108 avatar Nov 23 '25 00:11 lea108