This commit is contained in:
cottongin 2026-01-24 21:10:08 -05:00
parent 6bedc4ffec
commit 2b2bc95cf2
No known key found for this signature in database
GPG Key ID: 0ECC91FE4655C262
2 changed files with 26 additions and 5 deletions

View File

@ -193,11 +193,21 @@ 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());
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<Page>(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();
bool hasFailedLutRecords = false;

View File

@ -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);