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:
parent
a8e6e643f9
commit
d8bb51902f
10
src/HAP.cpp
10
src/HAP.cpp
|
|
@ -1285,14 +1285,18 @@ void HAPClient::checkTimedWrites(){
|
||||||
unsigned long cTime=millis(); // get current time
|
unsigned long cTime=millis(); // get current time
|
||||||
|
|
||||||
char c[64];
|
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
|
if(cTime>tw->second){ // timer has expired
|
||||||
sprintf(c,"Removing PID=%llu ALARM=%u\n",tw->first,tw->second);
|
sprintf(c,"Removing PID=%llu ALARM=%u\n",tw->first,tw->second);
|
||||||
LOG2(c);
|
LOG2(c);
|
||||||
homeSpan.TimedWrites.erase(tw);
|
tw=homeSpan.TimedWrites.erase(tw);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
tw++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue