Files
universal_ble/windows
Usman Mehmood 3f4abdc5cd Fix Windows crash by handling WinRT exceptions in BLE callback paths (#217)
* Fix Windows crash by handling WinRT exceptions in BLE callback paths

This patch hardens the Windows plugin against unhandled native exceptions that could terminate the Flutter process during reconnect/disconnect flows.

- add shared `log_and_swallow` helpers for consistent native exception logging
- wrap `ConnectAsync` in defensive `try/catch` blocks, including per-service characteristic discovery
- guard `BluetoothLeDeviceConnectionStatusChanged` to prevent callback exceptions from escaping
- harden `CleanConnection` and `DisposeServices` when unregistering handlers/subscriptions
- add explicit error handling around CCCD writes in `SetNotifiableAsync`
- wrap `GattCharacteristicValueChanged` notification callback path in `try/catch`
- add `ResetState()` helper scaffold for full native BLE state cleanup on Windows

* Added missing log to an empty catch statement

* fix(windows): report native callback failures as disconnect events

- emit `OnConnectionChanged(..., false, error)` on WinRT exceptions
- clean connection state before reporting disconnect

* Update windows/src/universal_ble_plugin.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update windows/src/universal_ble_plugin.cpp

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update windows/src/helper/utils.h

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update windows/src/helper/utils.h

---------

Co-authored-by: Navideck Labs <130186950+navidecklabs@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-11 17:15:38 +01:00
..
2024-01-24 14:23:49 +01:00
2024-01-24 14:23:49 +01:00
2026-01-05 16:12:31 +01:00