From 1595b3bd048497b77042ff12ce8eca43dc47d2a9 Mon Sep 17 00:00:00 2001 From: Martin Mueller Date: Thu, 22 Sep 2022 09:36:12 -0400 Subject: [PATCH] Fixed bug that caused a crash when sending graphpoint updates to multiple browsers. --- src/ESPUI.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/ESPUI.cpp b/src/ESPUI.cpp index 084a43a..b65998c 100644 --- a/src/ESPUI.cpp +++ b/src/ESPUI.cpp @@ -857,19 +857,24 @@ void ESPUIClass::clearGraph(uint16_t id, int clientId) { } void ESPUIClass::addGraphPoint(uint16_t id, int nValue, int clientId) { - Control* control = getControl(id); - if (!control) + do // once { - return; - } + Control* control = getControl(id); + if (!control) + { + break; + } - DynamicJsonDocument document(jsonUpdateDocumentSize); - JsonObject root = document.to(); + DynamicJsonDocument document(jsonUpdateDocumentSize); + JsonObject root = document.to(); - root[F("type")] = (int)ControlType::GraphPoint; - root[F("value")] = nValue; - root[F("id")] = control->id; - SendJsonDocToWebSocket(document, clientId); + root[F("type")] = (int)ControlType::GraphPoint; + root[F("value")] = nValue; + root[F("id")] = control->id; + + SendJsonDocToWebSocket(document, clientId); + + } while(false); } bool ESPUIClass::SendJsonDocToWebSocket(ArduinoJson::DynamicJsonDocument& document, uint16_t clientId) @@ -885,9 +890,9 @@ bool ESPUIClass::SendJsonDocToWebSocket(ArduinoJson::DynamicJsonDocument& docume } else { - for(auto& CurrentClient : MapOfClients) + for(auto CurrentClient : MapOfClients) { - Response |= MapOfClients[clientId]->SendJsonDocToWebSocket(document); + Response |= CurrentClient.second->SendJsonDocToWebSocket(document); } }