From 2b2bc95cf20fbd71c9ea2ba38689157328db0a01 Mon Sep 17 00:00:00 2001 From: cottongin Date: Sat, 24 Jan 2026 21:10:08 -0500 Subject: [PATCH] fixed --- lib/Epub/Epub/Section.cpp | 18 ++++++++++++++---- src/activities/reader/EpubReaderActivity.cpp | 13 ++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/lib/Epub/Epub/Section.cpp b/lib/Epub/Epub/Section.cpp index f346bd8..9f43321 100644 --- a/lib/Epub/Epub/Section.cpp +++ b/lib/Epub/Epub/Section.cpp @@ -193,10 +193,20 @@ bool Section::createSectionFile(const int fontId, const float lineCompression, c SdMan.remove(tmpHtmlPath.c_str()); if (!success) { - Serial.printf("[%lu] [SCT] Failed to parse XML and build pages\n", millis()); - file.close(); - SdMan.remove(filePath.c_str()); - return false; + Serial.printf("[%lu] [SCT] Failed to parse XML, creating placeholder page for chapter\n", millis()); + // Create a placeholder page for malformed chapters instead of failing entirely + // This allows the book to continue loading with chapters that do parse successfully + auto placeholderPage = std::unique_ptr(new Page()); + // Add placeholder to LUT + lut.emplace_back(this->onPageComplete(std::move(placeholderPage))); + + // If we still have no pages, the placeholder creation failed + if (pageCount == 0) { + Serial.printf("[%lu] [SCT] Failed to create placeholder page\n", millis()); + file.close(); + SdMan.remove(filePath.c_str()); + return false; + } } const uint32_t lutOffset = file.position(); diff --git a/src/activities/reader/EpubReaderActivity.cpp b/src/activities/reader/EpubReaderActivity.cpp index 832144e..47648a6 100644 --- a/src/activities/reader/EpubReaderActivity.cpp +++ b/src/activities/reader/EpubReaderActivity.cpp @@ -480,7 +480,7 @@ void EpubReaderActivity::renderScreen() { renderer.displayBuffer(EInkDisplay::FAST_REFRESH); }; - if (!section->createSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(), + if (!section->createSectionFile(SETTINGS.getReaderFontId(), SETTINGS.getReaderLineCompression(), SETTINGS.extraParagraphSpacing, SETTINGS.paragraphAlignment, viewportWidth, viewportHeight, SETTINGS.hyphenationEnabled, progressSetup, progressCallback)) { Serial.printf("[%lu] [ERS] Failed to persist page data to SD\n", millis()); @@ -524,6 +524,17 @@ void EpubReaderActivity::renderScreen() { section.reset(); return renderScreen(); } + + // Handle empty pages (e.g., from malformed chapters that couldn't be parsed) + if (p->elements.empty()) { + Serial.printf("[%lu] [ERS] Page has no content (possibly malformed chapter)\n", millis()); + renderer.drawCenteredText(UI_12_FONT_ID, 280, "Chapter content unavailable", true, EpdFontFamily::BOLD); + renderer.drawCenteredText(UI_10_FONT_ID, 320, "(File may be malformed)"); + renderStatusBar(orientedMarginRight, orientedMarginBottom, orientedMarginLeft); + renderer.displayBuffer(); + return; + } + const auto start = millis(); renderContents(std::move(p), orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft); Serial.printf("[%lu] [ERS] Rendered page in %dms\n", millis(), millis() - start);