Fix UI freeze/reboots: LVGL pool to PSRAM, dangling SSID buttons, scan policy
Firmware / build (push) Successful in 4m24s
Firmware / build (push) Successful in 4m24s
- lv_conf: LVGL widget pool 48 KB internal -> 512 KB PSRAM (LV_MEM_POOL_ALLOC). It ran out after a few Settings visits (87% used, 31% frag, 4.5 KB biggest block; lv_mem_buf_get() failed in a label draw - decoded backtrace). Also frees 48 KB of internal RAM: free 16 -> 69 KB, largest block 7.6 -> 31.7 KB - lv_conf: LV_ASSERT_HANDLER abort() instead of while(1), which spun inside the task holding the LVGL lock and froze the UI + console - wifi_manager: SSID buttons clear their g_ssid_buttons[] slot on LV_EVENT_DELETE (SquareLine deletes the Settings screen on leave; stale pointers were lv_obj_del()'d on the next scan). Scan only while the list is on screen and not connected - 10 s background scans caused the display dots - main: `mem` console command (internal heap, PSRAM, LVGL pool) - docs: board page lessons, open-questions #13/#14, ota-updates, CLAUDE.md, log Verified: 10 Settings visits + 9 list rebuilds, pool peak 4%, 0 crashes; user confirms no freeze, no reboot, no dots, swipes better. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -217,6 +217,16 @@ static void updateWifiUIState(wifi_state_t state) {
|
||||
* @brief Update SSID list with dynamic buttons
|
||||
* @note This function MUST be called with lvgl_port_lock held
|
||||
*/
|
||||
// The SSID buttons live on the Settings screen, which SquareLine deletes every
|
||||
// time it is left. Each button clears its own slot when LVGL deletes it, so
|
||||
// g_ssid_buttons[] never holds a freed pointer. Before this, the next scan
|
||||
// called lv_obj_del() on already-freed buttons, corrupting LVGL's heap until an
|
||||
// LVGL assert froze the UI (found 2026-09-27).
|
||||
static void onSsidButtonDeleted(lv_event_t* e) {
|
||||
intptr_t i = (intptr_t)lv_event_get_user_data(e);
|
||||
if (i >= 0 && i < WIFI_SCAN_MAX_NETWORKS) g_ssid_buttons[i] = NULL;
|
||||
}
|
||||
|
||||
static void updateSSIDList() {
|
||||
// This function MUST be called with lvgl_port_lock held
|
||||
|
||||
@@ -259,6 +269,7 @@ static void updateSSIDList() {
|
||||
|
||||
// Add click event handler
|
||||
lv_obj_add_event_cb(btn, onSSIDButtonClick, LV_EVENT_CLICKED, NULL);
|
||||
lv_obj_add_event_cb(btn, onSsidButtonDeleted, LV_EVENT_DELETE, (void*)(intptr_t)i);
|
||||
|
||||
// Store button reference
|
||||
g_ssid_buttons[i] = btn;
|
||||
@@ -421,9 +432,15 @@ static void wifiTask(void* parameter) {
|
||||
if (g_wifi_state != WIFI_STATE_OFF) {
|
||||
unsigned long current_time = millis();
|
||||
|
||||
// Start scan if requested or periodic scan is due
|
||||
if (g_wifi_scan_requested ||
|
||||
(current_time - g_last_scan_time > WIFI_SCAN_INTERVAL_MS && !scanning)) {
|
||||
// Scan only while the network list is on screen and we're not
|
||||
// connected. Scanning hops the radio across channels (ESP-NOW to B
|
||||
// shares it) and churns Wi-Fi buffers in PSRAM, which the RGB panel
|
||||
// streams from; it used to run every 10 s forever, connected or not,
|
||||
// on any screen. A pending request waits until the list is visible.
|
||||
bool list_on_screen = (uic_Wifi_Container != NULL);
|
||||
bool connected = (WiFi.status() == WL_CONNECTED);
|
||||
if (!scanning && list_on_screen && !connected &&
|
||||
(g_wifi_scan_requested || current_time - g_last_scan_time > WIFI_SCAN_INTERVAL_MS)) {
|
||||
|
||||
Serial.println("Starting WiFi scan...");
|
||||
scanning = true;
|
||||
|
||||
Reference in New Issue
Block a user