Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.
This repository was archived by the owner on Mar 30, 2019. It is now read-only.

Seeking advice on best way to gracefully handle device unplug / replug in DirectInput #979

Open
@evilC

Description

@evilC

It seems that if you are in a polling loop, eg repeatedly calling data = _joystick.GetBufferedData();, then if the stick is unplugged, an exception is thrown.
This is no problem, but my problem is how best to deal with this scenario.
If / when this happens, it seems that you are also unable to call UnAquire, I guess this is not an issue?
My main problem is how to detect that the device was plugged back in, if possible without having to enter a try catch block, as it would be nice for the poll loop to also be able to check for reconnect without having the perf overhead of trying to handle exceptions.
However, it seems that calling DiInstance.IsDeviceAttached(<guid>) (certainly when the device has just been unplugged) also throws.
I would also like to handle the scenario of a stick being plugged in after my poll loop starts, but the user could have declared bindings to say 10 sticks which are not plugged in yet, so how best to check, as rapidly as possible, with as little perf hit as possible, "did this stick get plugged in"?
At some point I plan on implementing device plug / unplug detection using USBHID or something, but for now if I can handle it reasonably gracefully from with SharpDX, that would be great.
Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions