NimBLEAdvertising::reset check if the stack is initialized before stop.

This prevents an exception when initializing a NimBLEAdvertising instance before calling NimBLEDevice::init().
The constructor calls reset() which calls stop(), if the stack was not yet initialized it will cause an exception.
This commit is contained in:
h2zero 2021-02-07 22:26:02 -07:00
parent dff5122ce2
commit 28d6492ea4

View file

@ -41,7 +41,9 @@ NimBLEAdvertising::NimBLEAdvertising() {
* @brief Stops the current advertising and resets the advertising data to the default values.
*/
void NimBLEAdvertising::reset() {
if(NimBLEDevice::getInitialized() && isAdvertising()) {
stop();
}
memset(&m_advData, 0, sizeof m_advData);
memset(&m_scanData, 0, sizeof m_scanData);
memset(&m_advParams, 0, sizeof m_advParams);