Open
Description
In the case that I was debugging, I am testing running the library on top of the USBHost_t36 code on Teensy 3.6 or 4.x.
It works with some Bluetooth dongles and not others. In the case I am debugging it faults when I use a CSR 4.0 dongle.
I traced it to the call:
if (HCI.setLeEventMask(0x00000000000003FF) != 0) {
end();
return 0;
}
It failed with error code 0x12.
The call to end() ends up faulting.
The reason GATT.begin();
has not been called. It is called near the end of the BLELocalDevice::begin() ,
And BLELocalDevice::end() calls GATT.end.
void BLELocalDevice::end()
{
GATT.end();
...
And GAT.end() calls off and deletes objects which have not yet been created.
void GATTClass::end()
{
if (_genericAccessService->release() == 0)
delete(_genericAccessService);
if (_deviceNameCharacteristic->release() == 0)
delete(_deviceNameCharacteristic);
if (_appearanceCharacteristic->release() == 0)
delete(_appearanceCharacteristic);
if (_genericAttributeService->release() == 0)
delete(_genericAttributeService);
if (_servicesChangedCharacteristic->release() == 0)
delete(_servicesChangedCharacteristic);
clearAttributes();
}
Possible fixes:
- Don't call GATT.end() if begin has not yet been called.
- Change the GATT code to check before calling...
like:
if (_genericAccessService && (_genericAccessService->release() == 0))
delete(_genericAccessService);
Wondering if is the same issue, that is mentioned in #273