From 21feec09720379ccf0af89d1bd5d36958ba5935b Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:52:11 +0200 Subject: [PATCH] fix(l2): wait out the tile being read before the SD card is unmounted USB drive and Format card closed the open map pack and unmounted, while the tile task could still be reading a tile off the card (a map left open, a prefetch). Both now wait for it first, as the map's own redraw does. Co-Authored-By: Claude Opus 5.5 --- examples/companion_radio/ui-lvgl/StorageScreen.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/companion_radio/ui-lvgl/StorageScreen.h b/examples/companion_radio/ui-lvgl/StorageScreen.h index ab76933d..115976fe 100644 --- a/examples/companion_radio/ui-lvgl/StorageScreen.h +++ b/examples/companion_radio/ui-lvgl/StorageScreen.h @@ -55,6 +55,14 @@ static void stopWalk() { s_walking = false; } +// Before the card is unmounted: let the tile task finish the tile it may still +// be reading off it (from a map left open, or a prefetch), then close the map +// pack it reads from. +static void releaseMapFiles() { + while (mapview::s_cache.busy()) { delay(5); mapview::pollTiles(); } + mapview::s_vpacks.closeOpen(); +} + static void startWalk() { stopWalk(); memset(s_bytes, 0, sizeof(s_bytes)); @@ -414,7 +422,7 @@ void UITask::storageFormatTap(bool go) { lv_refr_now(NULL); // shown before the loop blocks stopWalk(); if (mapview::s_dl.active()) mapDownloadStop(); - mapview::s_vpacks.closeOpen(); + storeview::releaseMapFiles(); bool ok = lvport::formatCard(); if (!ok) { if (s_fmt_overlay) lv_obj_delete_async(s_fmt_overlay); @@ -505,7 +513,7 @@ void UITask::usbTap(bool drive) { if (!drive || locked()) return; storeview::stopWalk(); if (mapview::s_dl.active()) mapDownloadStop(); - mapview::s_vpacks.closeOpen(); // a pack file kept open between reads: not across the unmount + storeview::releaseMapFiles(); // the tile being read and the pack kept open: not across the unmount if (!lvport::usbDriveStart()) { showToast("No SD card to share", 3000); return; } usbPanel("USB drive", "The computer has the SD card now. Eject it there (or unplug the cable) when you're done - "