From b3d3685685589028150ab6607e8a1e25c5a3cb7b Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 3 Aug 2023 16:17:36 -0400 Subject: [PATCH] Fix crash when an error happens during a BLE scan on darwin. (#28505) If we happened to do a BLE scan after doing a BLE connect, and then during the BLE scan one of two things happens: 1. Bluetooth is shut down (e.g. by just turning it off via the menubar). 2. The scan is a delegate-less scan and times out. then we would try to use the error handler that expects a SetUpCodePairer but without an actual non-null SetUpCodePairer to pass it. And then that would crash. The fix is to not call an error handler that we're not supposed to be calling; scans do not call the _connection_ error handler. --- src/platform/Darwin/BleConnectionDelegateImpl.mm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/platform/Darwin/BleConnectionDelegateImpl.mm b/src/platform/Darwin/BleConnectionDelegateImpl.mm index 8baed2da9be929..1d4e76618ac321 100644 --- a/src/platform/Darwin/BleConnectionDelegateImpl.mm +++ b/src/platform/Darwin/BleConnectionDelegateImpl.mm @@ -181,8 +181,10 @@ - (void)removePeripheralsFromCache; [ble stop]; ble = [[BleConnection alloc] initWithDelegate:delegate queue:bleWorkQueue]; - ble.onConnectionComplete = OnConnectionComplete; - ble.onConnectionError = OnConnectionError; + // Do _not_ set onConnectionComplete and onConnectionError + // here. The connection callbacks we have expect an appState + // that we do not have here, and in any case connection + // complete/error make no sense for a scan. ble.centralManager = [ble.centralManager initWithDelegate:ble queue:bleWorkQueue]; }); }