buttplug-csharp icon indicating copy to clipboard operation
buttplug-csharp copied to clipboard

Can't close Win10 Bluetooth LE device connections without exiting process

Open qdot opened this issue 8 years ago • 1 comments

Bluetooth device connections in UWP are managed via what is supposed to be a black boxed RAII situation. Whenever all connection objects (bluetoothLEDevice/Service/GattCharacteristic) are dropped, and .Dispose is called on the bluetoothLEDevice object, the device should disconnect.

This does not seem to be the case with any device that we support with Buttplug C#. Neither the launch nor the lovense toys drop a connection, even when using a minimal test that just finds a device and opens a service/characteristic with no buttplug code. The ONLY way the device closes is on process exit. I think this may be a Win10 bug, or something with the way we're using UWP APIs from WPF (which is supported, but jank as fuck apparently. See the registry crap we have to do for more info on that).

Here's a gist with a test for trying this with the Launch, that pauses multiple times for debug stepping/memory snapshotting: https://gist.github.com/qdot/58f0bff74e604b8cf462734b956f50d9

There's multiple possible solutions to this. The one we're going with right now is #193, which will at least get us to v0.1, but isn't pretty. One option is to have some sort of device process pool so that when we shutdown a device, the process goes with it, clearing memory and actually closing the device. This sucks though as it's yet another protocol to implement and maintain. Another is to just pray MS fixes their shit. We'll file this to the MSDN forums and see if we get any response.

qdot avatar Jul 15 '17 07:07 qdot

This is still a problem. :|

qdot avatar Sep 22 '18 06:09 qdot

Moving to client only impl. Marking wontfix and closing.

Though as an aside: This was only fixed in a patch in 2022 for the rust library. :|

qdot avatar Dec 27 '22 21:12 qdot