From fd0187bfc9f4773bd018d15dea830d995f13deaf Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Fri, 20 Dec 2024 13:16:27 -0600 Subject: [PATCH] Fix crash that could occur when server reconnects * Update to not change services if they have not actually changed when starting the server Closes #270 --- src/NimBLEService.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/NimBLEService.cpp b/src/NimBLEService.cpp index 577a45f..49eef01 100644 --- a/src/NimBLEService.cpp +++ b/src/NimBLEService.cpp @@ -91,6 +91,13 @@ void NimBLEService::dump() const { */ bool NimBLEService::start() { NIMBLE_LOGD(LOG_TAG, ">> start(): Starting service: %s", toString().c_str()); + + // If started previously and no characteristics have been added or removed, + // then we can skip the service registration process. + if (m_pSvcDef->characteristics && !getServer()->m_svcChanged) { + return true; + } + // If started previously, clear everything and start over if (m_pSvcDef->characteristics) { if (m_pSvcDef->characteristics->descriptors) {