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.
This commit is contained in:
Eunchurn Park
2026-01-18 18:56:53 +09:00
parent c0057900eb
commit 00134bbe80

View File

@@ -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;
}
{