From d5b79cf0b4ba2ade9ef983c3758590fcd76e8914 Mon Sep 17 00:00:00 2001 From: pelgraine <140762863+pelgraine@users.noreply.github.com> Date: Tue, 24 Feb 2026 02:17:42 +1100 Subject: [PATCH] fix ble error loop crash in serialbleinterface and main; same ble crash fix in webreaderscreen --- examples/companion_radio/main.cpp | 11 +- .../companion_radio/ui-new/Webreaderscreen.h | 102 ++++++++++++++---- src/helpers/esp32/SerialBLEInterface.cpp | 14 ++- 3 files changed, 102 insertions(+), 25 deletions(-) diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index f30a7e6..4aa1f1a 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -1400,11 +1400,18 @@ void handleKeyboardInput() { Serial.printf("WebReader: heap BEFORE BT release: free=%d, largest=%d\n", ESP.getFreeHeap(), ESP.getMaxAllocHeap()); - // 1) Stop BLE controller (disable + deinit) + // 1) Gracefully disable BLE interface (stop advertising, disconnect, clear queues) + // Must happen BEFORE btStop() while BLE objects are still valid + #ifdef BLE_PIN_CODE + serial_interface.disable(); + delay(50); + #endif + + // 2) Stop BLE controller (disable + deinit) btStop(); delay(50); - // 2) Release the BT controller's reserved memory region back to heap + // 3) Release the BT controller's reserved memory region back to heap esp_bt_controller_mem_release(ESP_BT_MODE_BTDM); delay(50); diff --git a/examples/companion_radio/ui-new/Webreaderscreen.h b/examples/companion_radio/ui-new/Webreaderscreen.h index c097f5f..f39c78d 100644 --- a/examples/companion_radio/ui-new/Webreaderscreen.h +++ b/examples/companion_radio/ui-new/Webreaderscreen.h @@ -442,6 +442,7 @@ inline ParseResult parseHtml(const char* html, int htmlLen, char pendingLabel[48] = {0}; bool inLabel = false; int labelTextStart = 0; + int listDepth = 0; // Nesting depth of