PhilipsHue / flutter_reactive_ble

Flutter library that handles BLE operations for multiple devices.
https://developers.meethue.com/
Other
667 stars 331 forks source link

scanForDevices in statusStream causes an error #714

Open panhboth111 opened 1 year ago

panhboth111 commented 1 year ago

Describe the bug I tried to nest the scanForDevices method inside the statusStream in order to only scan for the devices when the ble status is ready

ble.statusStream.listen((BleStatus status) {
      if (status == BleStatus.ready) {
        ble.scanForDevices(withServices: []).listen((event) {});
      }
 });

By doing this, I received the following error:

reactive_ble_mobile/PluginController.swift:158: Assertion failed
reactive_ble_mobile/PluginController.swift:158: Assertion failed
* thread #1, queue = 'com.apple.main-thread', stop reason = Assertion failed
    frame #0: 0x00000001cbe390f8 libswiftCore.dylib`_swift_runtime_on_report
libswiftCore.dylib`:
->  0x1cbe390f8 <+0>: ret    
libswiftCore.dylib`:
    0x1cbe390fc <+0>: b      0x1cbe390f8               ; _swift_runtime_on_report
libswiftCore.dylib`:
    0x1cbe39100 <+0>: adrp   x8, 365868
    0x1cbe39104 <+4>: ldrb   w0, [x8, #0xabc]
Target 0: (Runner) stopped.
maBarabas commented 1 year ago

I found the same crash just by starting two scans at the same time. The failing assertion is assert(!central.isScanning).

maBarabas commented 1 year ago

This is the same issue described in https://github.com/PhilipsHue/flutter_reactive_ble/issues/221 and https://github.com/PhilipsHue/flutter_reactive_ble/issues/283.