Fix timing overflow when components disable themselves during loop (#9529)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
J. Nick Koston 2025-07-15 11:51:01 -10:00 committed by Jesse Hills
parent 18e2f41424
commit 8c8c08d40c
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A

View File

@ -309,6 +309,12 @@ void Application::disable_component_loop_(Component *component) {
if (this->in_loop_ && i == this->current_loop_index_) {
// Decrement so we'll process the swapped component next
this->current_loop_index_--;
// Update the loop start time to current time so the swapped component
// gets correct timing instead of inheriting stale timing.
// This prevents integer underflow in timing calculations by ensuring
// the swapped component starts with a fresh timing reference, avoiding
// errors caused by stale or wrapped timing values.
this->loop_component_start_time_ = millis();
}
}
return;