From 28d6492ea44bd24722c3c7515dd3b5226cd67cb4 Mon Sep 17 00:00:00 2001 From: h2zero Date: Sun, 7 Feb 2021 22:26:02 -0700 Subject: [PATCH] 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. --- src/NimBLEAdvertising.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/NimBLEAdvertising.cpp b/src/NimBLEAdvertising.cpp index 81ce79c..08493d1 100644 --- a/src/NimBLEAdvertising.cpp +++ b/src/NimBLEAdvertising.cpp @@ -41,7 +41,9 @@ NimBLEAdvertising::NimBLEAdvertising() { * @brief Stops the current advertising and resets the advertising data to the default values. */ void NimBLEAdvertising::reset() { - stop(); + 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);