From 6a9bd9673a43d9b806b4240bf9f068f154c8a282 Mon Sep 17 00:00:00 2001 From: Yurii Date: Sun, 10 Nov 2024 01:32:42 +0300 Subject: [PATCH] fix: ``Sensors::cleanDallasInstances()`` fixed --- src/SensorsTask.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/SensorsTask.h b/src/SensorsTask.h index 1f1208f..6eef520 100644 --- a/src/SensorsTask.h +++ b/src/SensorsTask.h @@ -119,7 +119,10 @@ protected: } void cleanDallasInstances() { - for (auto& [gpio, instance] : this->dallasInstances) { + // for (auto& [gpio, instance] : this->dallasInstances) { + auto it = this->dallasInstances.begin(); + while (it != this->dallasInstances.end()) { + auto gpio = it->first; bool instanceUsed = false; for (uint8_t sensorId = 0; sensorId <= Sensors::getMaxSensorId(); sensorId++) { @@ -135,8 +138,8 @@ protected: } } - if (!instanceUsed) {; - this->dallasInstances.erase(gpio); + if (!instanceUsed) { + it = this->dallasInstances.erase(it); this->owInstances.erase(gpio); this->dallasSearchTime.erase(gpio); this->dallasPolling.erase(gpio); @@ -145,6 +148,8 @@ protected: Log.sinfoln(FPSTR(L_SENSORS_DALLAS), F("Stopped on GPIO %hhu"), gpio); continue; } + + it++; } }