Skip to content

fix(epub): avoid crashes when CSS cache is missing#762

Open
DChells wants to merge 5 commits intocrosspoint-reader:masterfrom
DChells:fix/epub-css-crash
Open

fix(epub): avoid crashes when CSS cache is missing#762
DChells wants to merge 5 commits intocrosspoint-reader:masterfrom
DChells:fix/epub-css-crash

Conversation

@DChells
Copy link
Contributor

@DChells DChells commented Feb 8, 2026

Summary

Prevents EPUB reader reboot loops when css_rules.cache is missing, and stops Home from repeatedly retrying cover thumbnail generation for unsupported EPUB cover images.

Fixes #761.

Problem

Two issues that show up most often on ESP32-C3 with large EPUBs:

  1. CSS cache miss can crash the reader
  • If /.crosspoint/epub_<hash>/css_rules.cache is missing, we try to parse CSS on-demand.
  • On large books / tight heap this can throw/abort and the device ends up reboot-looping.
  1. Home periodically pauses with a "Loading..." popup
  • Home attempts to generate thumb_<height>.bmp for recent book covers.
  • Some EPUB covers are progressive JPEGs, which picojpeg doesn’t support (error 37 / PJPG_UNSUPPORTED_MODE).
  • Since the thumb never appears, Home keeps retrying on subsequent renders → periodic pauses.

Solution

  • CSS cache miss: fail open (continue without CSS) instead of crashing
    • Skip CSS parsing on cache-miss when the book is large or free heap is low
    • Guard best-effort CSS parsing so exceptions don’t crash the device
  • Home thumbnails:
    • If JPEG decode fails, write a 0-byte thumb sentinel so Home stops retrying forever
    • Lyra theme: when cover is missing/invalid, render a simple placeholder with the book title in the cover box
  • Metadata reads / recents migration: always skip CSS parsing (metadata only)

Notes / tradeoffs

  • On books that hit the “skip CSS parse” path, rendering may be less styled (we intentionally skip building CSS rules to prioritize stability over perfect styling).
  • For progressive JPEG covers, we intentionally stop retrying; users can convert the cover to baseline JPEG if they want the thumb.

Testing

On hardware (Xteink X4 / ESP32-C3):

  • Delete /.crosspoint/epub_<hash>/css_rules.cache for a large EPUB, then open it → should not reboot; should log skipping CSS parse
  • Return to Home repeatedly → should not keep retrying thumb generation for the same book/thumb size
  • Verify Lyra Home shows title fallback when cover thumb is missing/invalid

Files changed

  • lib/Epub/Epub.cpp
  • src/RecentBooksStore.cpp
  • src/components/themes/lyra/LyraTheme.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix crash when EPUB CSS cache missing + avoid repeated cover thumb generation

1 participant