Fix: Footnotes crashes after Screen→Activity refactor

This commit is contained in:
Jérôme Launay 2025-12-17 23:46:01 +01:00
parent b2985f87d3
commit 91a0677503
2 changed files with 27 additions and 12 deletions

View File

@ -46,7 +46,6 @@ void EpubReaderActivity::onEnter() {
nextPageNumber = data[2] + (data[3] << 8); nextPageNumber = data[2] + (data[3] << 8);
Serial.printf("[%lu] [ERS] Loaded cache: %d, %d\n", millis(), currentSpineIndex, nextPageNumber); Serial.printf("[%lu] [ERS] Loaded cache: %d, %d\n", millis(), currentSpineIndex, nextPageNumber);
f.close(); f.close();
f.close();
} }
// Trigger first update // Trigger first update
@ -322,11 +321,16 @@ void EpubReaderActivity::renderScreen() {
return renderScreen(); return renderScreen();
} }
Serial.printf("[%lu] [ERS] Page loaded: %d elements, %d footnotes\n",
millis(), p->elementCount, p->footnoteCount);
// Copy footnotes from page to currentPageFootnotes // Copy footnotes from page to currentPageFootnotes
currentPageFootnotes.clear(); currentPageFootnotes.clear();
for (int i = 0; i < p->footnoteCount && i < 16; i++) { int maxFootnotes = (p->footnoteCount < 16) ? p->footnoteCount : 16;
for (int i = 0; i < maxFootnotes; i++) {
FootnoteEntry* footnote = p->getFootnote(i); FootnoteEntry* footnote = p->getFootnote(i);
if (footnote) { if (footnote && footnote->href[0] != '\0') {
currentPageFootnotes.addFootnote(footnote->number, footnote->href); currentPageFootnotes.addFootnote(footnote->number, footnote->href);
} }
} }

View File

@ -8,14 +8,19 @@
class FootnotesData { class FootnotesData {
private: private:
FootnoteEntry entries[32]; FootnoteEntry entries[16];
int count; int count;
public: public:
FootnotesData() : count(0) {} FootnotesData() : count(0) {
for (int i = 0; i < 16; i++) {
entries[i].number[0] = '\0';
entries[i].href[0] = '\0';
}
}
void addFootnote(const char* number, const char* href) { void addFootnote(const char* number, const char* href) {
if (count < 32) { if (count < 16 && number && href) {
strncpy(entries[count].number, number, 2); strncpy(entries[count].number, number, 2);
entries[count].number[2] = '\0'; entries[count].number[2] = '\0';
strncpy(entries[count].href, href, 63); strncpy(entries[count].href, href, 63);
@ -24,7 +29,13 @@ class FootnotesData {
} }
} }
void clear() { count = 0; } void clear() {
count = 0;
for (int i = 0; i < 16; i++) {
entries[i].number[0] = '\0';
entries[i].href[0] = '\0';
}
}
int getCount() const { return count; } int getCount() const { return count; }