Fixed Bug in TimedWrites

The loop over TimedWrites incorrectly erased iterators inside a for-loop.  For some reason this never caused an issue on the ESP32, but crashed on the ESP32-C3.  Solution is to change the for-loop to a while-loop with proper handling of the iterator when an element is deleted.  This appears to fix the problem.
This commit is contained in:
Gregg 2021-11-24 18:27:55 -06:00
parent a8e6e643f9
commit d8bb51902f
1 changed files with 7 additions and 3 deletions

View File

@ -1285,14 +1285,18 @@ void HAPClient::checkTimedWrites(){
unsigned long cTime=millis(); // get current time
char c[64];
for(auto tw=homeSpan.TimedWrites.begin(); tw!=homeSpan.TimedWrites.end(); tw++){ // loop over all Timed Writes using an iterator
auto tw=homeSpan.TimedWrites.begin();
while(tw!=homeSpan.TimedWrites.end()){
if(cTime>tw->second){ // timer has expired
sprintf(c,"Removing PID=%llu ALARM=%u\n",tw->first,tw->second);
LOG2(c);
homeSpan.TimedWrites.erase(tw);
tw=homeSpan.TimedWrites.erase(tw);
}
else
tw++;
}
}
//////////////////////////////////////