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);
Serial.printf("[%lu] [ERS] Loaded cache: %d, %d\n", millis(), currentSpineIndex, nextPageNumber);
f.close();
f.close();
}
// Trigger first update
@ -322,11 +321,16 @@ void EpubReaderActivity::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
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);
if (footnote) {
if (footnote && footnote->href[0] != '\0') {
currentPageFootnotes.addFootnote(footnote->number, footnote->href);
}
}

View File

@ -7,15 +7,20 @@
#include "../Activity.h"
class FootnotesData {
private:
FootnoteEntry entries[32];
private:
FootnoteEntry entries[16];
int count;
public:
FootnotesData() : count(0) {}
public:
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) {
if (count < 32) {
if (count < 16 && number && href) {
strncpy(entries[count].number, number, 2);
entries[count].number[2] = '\0';
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; }
@ -42,7 +53,7 @@ class EpubReaderFootnotesActivity final : public Activity {
const std::function<void(const char*)> onSelectFootnote;
int selectedIndex;
public:
public:
EpubReaderFootnotesActivity(GfxRenderer& renderer, InputManager& inputManager, const FootnotesData& footnotes,
const std::function<void()>& onGoBack,
const std::function<void(const char*)>& onSelectFootnote)
@ -56,6 +67,6 @@ class EpubReaderFootnotesActivity final : public Activity {
void onExit() override;
void loop() override;
private:
private:
void render();
};