Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash after device disconnects #62

Open
rib opened this issue Sep 10, 2021 · 0 comments
Open

Crash after device disconnects #62

rib opened this issue Sep 10, 2021 · 0 comments

Comments

@rib
Copy link

rib commented Sep 10, 2021

If I connect to a heart rate monitor and enable notifications for the heart rate characteristic and then wait for the device to go idle and disconnect I see a crash if I try to navigate back to the heart rate characteristic due to this exception:

System.ObjectDisposedException
  HResult=0x80000013
  Message=The object has been closed. (Exception from HRESULT: 0x80000013)
  Source=Windows
  StackTrace:
   at Windows.Devices.Bluetooth.GenericAttributeProfile.GattCharacteristic.get_Service()
   at BluetoothLEExplorer.ViewModels.CharacteristicPageViewModel.get_CharacteristicCanWrite() in C:\Users\Robert\src\BluetoothLEExplorer\BluetoothLEExplorer\BluetoothLEExplorer\ViewModels\CharacteristicPageViewModel.cs:line 302
   at BluetoothLEExplorer.Views.CharacteristicPage.CharacteristicPage_obj1_Bindings.Update_ViewModel(CharacteristicPageViewModel obj, Int32 phase) in C:\Users\Robert\src\BluetoothLEExplorer\BluetoothLEExplorer\BluetoothLEExplorer\obj\x86\Debug\Views\CharacteristicPage.g.cs:line 814
   at BluetoothLEExplorer.Views.CharacteristicPage.CharacteristicPage_obj1_Bindings.Update_(CharacteristicPage obj, Int32 phase) in C:\Users\Robert\src\BluetoothLEExplorer\BluetoothLEExplorer\BluetoothLEExplorer\obj\x86\Debug\Views\CharacteristicPage.g.cs:line 791
   at BluetoothLEExplorer.Views.CharacteristicPage.CharacteristicPage_obj1_Bindings.Update() in C:\Users\Robert\src\BluetoothLEExplorer\BluetoothLEExplorer\BluetoothLEExplorer\obj\x86\Debug\Views\CharacteristicPage.g.cs:line 733
   at BluetoothLEExplorer.Views.CharacteristicPage.CharacteristicPage_obj1_Bindings.Initialize() in C:\Users\Robert\src\BluetoothLEExplorer\BluetoothLEExplorer\BluetoothLEExplorer\obj\x86\Debug\Views\CharacteristicPage.g.cs:line 727
   at BluetoothLEExplorer.Views.CharacteristicPage.CharacteristicPage_obj1_Bindings.Loading(FrameworkElement src, Object data) in C:\Users\Robert\src\BluetoothLEExplorer\BluetoothLEExplorer\BluetoothLEExplorer\obj\x86\Debug\Views\CharacteristicPage.g.cs:line 761

This issue is actually also very closely related to a problem I'm seeing in my own project where I get the same ObjectDisposedException exception if I try and interact with a GattCharacteristic after reconnecting to a heart rate monitor (In my case when I try and re-enable notifications for a characteristic after reconnecting I get this exception).

I was hoping that BluetoothLEExplorer might help clarify how the winrt API is supposed to be used when it comes to handling device disconnections because I can't find any documentation on the lifecycle of GattDeviceService and GattCharacteristic instances and I don't really know if they are supposed to remain valid across device reconnects (I had previously assumed yes because in general the API seems to try and abstract the underlying connection away).

Empirically I see that GattDeviceService instances remain usable across reconnects so it seems a little surprising that the same wouldn't be expected from GattCharacteristic instances?

Hoping someone here will have a better understand of what's expected here 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant