From 6e9ebf6b1bedacb410f1435f72d4a89463a03fbb Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 31 Mar 2026 21:43:21 -1000 Subject: [PATCH] Fix scoping: declare count outside portENTER_CRITICAL block BK72xx portENTER_CRITICAL expands to something that introduces a scope, so variables declared between ENTER/EXIT are not visible after. --- esphome/core/freertos_queue.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esphome/core/freertos_queue.h b/esphome/core/freertos_queue.h index 38e764137e..9875606210 100644 --- a/esphome/core/freertos_queue.h +++ b/esphome/core/freertos_queue.h @@ -61,8 +61,10 @@ template class FreeRTOSQueue { // Drops are rare so almost always returns 0 without entering a critical section. if (this->dropped_count_ == 0) return 0; + // Declare outside critical section — BK72xx portENTER_CRITICAL may introduce a scope + uint16_t count; portENTER_CRITICAL(); - uint16_t count = this->dropped_count_; + count = this->dropped_count_; this->dropped_count_ = 0; portEXIT_CRITICAL(); return count;