From eb75b4a82e95a582f763dd8f20354e2ec0684f5d Mon Sep 17 00:00:00 2001 From: Eunchurn Park Date: Sat, 27 Dec 2025 00:17:41 +0900 Subject: [PATCH] fix(parser): remove MAX_LINES limit that truncates long chapters The MAX_LINES=1000 limit was causing text to disappear after ~25 pages in long chapters. For example, a 93KB chapter generating 242 pages (~9,680 lines) was being truncated at ~1000 lines. Replaced the hard limit with a safety check that prevents infinite loops by forcing advancement when nextBreakIndex doesn't progress, while still allowing all lines to be processed. --- lib/Epub/Epub/ParsedText.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Epub/Epub/ParsedText.cpp b/lib/Epub/Epub/ParsedText.cpp index d73f80a..c2f13d8 100644 --- a/lib/Epub/Epub/ParsedText.cpp +++ b/lib/Epub/Epub/ParsedText.cpp @@ -111,16 +111,17 @@ std::vector ParsedText::computeLineBreaks(const int pageWidth, const int // Stores the index of the word that starts the next line (last_word_index + 1) std::vector lineBreakIndices; size_t currentWordIndex = 0; - constexpr size_t MAX_LINES = 1000; while (currentWordIndex < totalWordCount) { - if (lineBreakIndices.size() >= MAX_LINES) { - break; + size_t nextBreakIndex = ans[currentWordIndex] + 1; + + // Safety check: prevent infinite loop if nextBreakIndex doesn't advance + if (nextBreakIndex <= currentWordIndex) { + // Force advance by at least one word to avoid infinite loop + nextBreakIndex = currentWordIndex + 1; } - size_t nextBreakIndex = ans[currentWordIndex] + 1; lineBreakIndices.push_back(nextBreakIndex); - currentWordIndex = nextBreakIndex; }