OpenBluetoothToolbox / SimpleBLE

SimpleBLE - the all-in-one Bluetooth library for MacOS, iOS, Windows, Linux and Android.
https://www.simpleble.org
Other
655 stars 110 forks source link

The C library occasionally crashes when simpleble_peripheral_manufacturer_data_get is called #267

Open KlemenDEV opened 10 months ago

KlemenDEV commented 10 months ago

I am in the process of making Java bindings for the library using JNA via SimpleBLE C API.

I have implemented quite some parts of it already, but I am facing a problem where the library crashes (JVM) when simpleble_peripheral_manufacturer_data_get is called. This does not happen every time a new device is found, but only after a few detections usually.

The implementation follows https://github.com/OpenBluetoothToolbox/SimpleBLE/blob/main/examples/simpleble/c/scan.c

Such a problem is not observed when obtaining services via simpleble_peripheral_services_get with the same mechanism except, of course, a different method and structure type.

I did not figure out how to get stack trace or core dump when calling via JNA yet so I don't have more details on the crash, but they happen when the peripheral has manufacturer data (simpleble_peripheral_manufacturer_data_count > 0) and then simpleble_peripheral_manufacturer_data_get is called.

I have also observed I get different numbers of data for simpleble_peripheral_manufacturer_data_count for the same peripheral where the peripheral is sending the same number of manufacturer data entries in the BLE ADV.

Testing on Windows 11

KlemenDEV commented 10 months ago

It also seems that calling simpleble_peripheral_manufacturer_data_get, structure sometimes gets the data array filled with non-zero values, while the data_length is set to 0

KlemenDEV commented 10 months ago

Checking value of the manufacturer_data, there sometimes can be found short sequences of correct data, but not full chunks

Missing advertisements could be similar to #218, however same BLE adapter always reads all manufacturer data when testing with eg. Bleak Python library