refactor: Memory optimization and XTC format removal

Memory optimization:
- Add LOG_STACK_WATERMARK macro for task stack monitoring
- Add freeCoverBufferIfAllocated() and preloadCoverBuffer() for memory management
- Improve cover buffer reuse to reduce heap fragmentation
- Add grayscale buffer cleanup safety in GfxRenderer
- Make grayscale rendering conditional on successful buffer allocation
- Add detailed heap fragmentation logging with ESP-IDF API
- Add CSS parser memory usage estimation

XTC format removal:
- Remove entire lib/Xtc library (XTC parser and types)
- Remove XtcReaderActivity and XtcReaderChapterSelectionActivity
- Remove XTC file handling from HomeActivity, SleepActivity, ReaderActivity
- Remove .xtc/.xtch from supported extensions in BookManager
- Remove XTC cache prefix from Md5Utils
- Update web server and file browser to exclude XTC format
- Clear in-memory caches when disk cache is cleared
This commit is contained in:
cottongin
2026-01-27 20:35:32 -05:00
parent 158caacfe0
commit c2a966a6ea
30 changed files with 201 additions and 2624 deletions

View File

@@ -857,7 +857,7 @@ bool GfxRenderer::storeBwBuffer() {
* Uses chunked restoration to match chunked storage.
*/
void GfxRenderer::restoreBwBuffer() {
// Check if any all chunks are allocated
// Check if all chunks are allocated
bool missingChunks = false;
for (const auto& bwBufferChunk : bwBufferChunks) {
if (!bwBufferChunk) {
@@ -868,6 +868,13 @@ void GfxRenderer::restoreBwBuffer() {
if (missingChunks) {
freeBwBufferChunks();
// CRITICAL: Even if restore fails, we must clean up the grayscale state
// to prevent grayscaleRevert() from being called with corrupted RAM state
// Use the current framebuffer content (which may not be ideal but prevents worse issues)
uint8_t* frameBuffer = einkDisplay.getFrameBuffer();
if (frameBuffer) {
einkDisplay.cleanupGrayscaleBuffers(frameBuffer);
}
return;
}
@@ -883,6 +890,8 @@ void GfxRenderer::restoreBwBuffer() {
if (!bwBufferChunks[i]) {
Serial.printf("[%lu] [GFX] !! BW buffer chunks not stored - this is likely a bug\n", millis());
freeBwBufferChunks();
// CRITICAL: Clean up grayscale state even on mid-restore failure
einkDisplay.cleanupGrayscaleBuffers(frameBuffer);
return;
}