Skip to content

Crash after device disconnects #62

@rib

Description

@rib

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 🤞

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions