From 00134bbe80d520c22917a2993bbe5e1f34a71192 Mon Sep 17 00:00:00 2001 From: Eunchurn Park Date: Sun, 18 Jan 2026 18:56:53 +0900 Subject: [PATCH] fix: Clamp page number when out of bounds after font change When font changes cause different page counts, the cached page number may exceed the new page count. Instead of showing 'Out of bounds' error, clamp to the last page of the section. --- src/activities/reader/EpubReaderActivity.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/activities/reader/EpubReaderActivity.cpp b/src/activities/reader/EpubReaderActivity.cpp index 2eeba80f..6016965b 100644 --- a/src/activities/reader/EpubReaderActivity.cpp +++ b/src/activities/reader/EpubReaderActivity.cpp @@ -340,11 +340,11 @@ void EpubReaderActivity::renderScreen() { } if (section->currentPage < 0 || section->currentPage >= section->pageCount) { - Serial.printf("[%lu] [ERS] Page out of bounds: %d (max %d)\n", millis(), section->currentPage, section->pageCount); - renderer.drawCenteredText(UI_12_FONT_ID, 300, "Out of bounds", true, EpdFontFamily::BOLD); - renderStatusBar(orientedMarginRight, orientedMarginBottom, orientedMarginLeft); - renderer.displayBuffer(); - return; + // Page out of bounds - likely due to font change causing different page count + // Clamp to valid range instead of showing error + Serial.printf("[%lu] [ERS] Page out of bounds: %d (max %d), clamping to last page\n", millis(), + section->currentPage, section->pageCount); + section->currentPage = section->pageCount - 1; } {