From 884c570424d1630d8a2019c78f22c57e7cf18a5b Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Wed, 19 Aug 2026 08:03:38 -0400 Subject: [PATCH] Fix crash on progress pull: gotoPercent is not a document method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pulling progress crashed KOReader in syncToProgress when the target wasn't a page number or xpointer (e.g. an epubcfi string from the server on a rolling document, falling to the percentage branch): 'attempt to call method gotoPercent (a nil value)'. Documents have no such method — navigation goes through events, exactly as the other branches in this function already do. The percentage fallback now dispatches Event GotoPercent (0-100), handled by ReaderRolling:onGotoPercent and ReaderPaging:onGotoPercent (the built-in Go-to-% handlers, which also refresh the view). The redundant UpdatePos follow-up is gone; handlers do it. Verified all four paths in the stub harness: rolling+percentage → Event:GotoPercent, rolling+xpointer → Event:GotoXPointer, paging+ page → Event:GotoPage, paging+unresolvable → no-op. No crashes. --- main.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.lua b/main.lua index ca277da..b0907a0 100644 --- a/main.lua +++ b/main.lua @@ -909,8 +909,11 @@ function Bookhoard:syncToProgress(progress, percentage) elseif progress and progress:match("^/body/") then self.ui:handleEvent(Event:new("GotoXPointer", progress)) elseif percentage then - self.ui.document:gotoPercent(percentage * 100) - self.ui:handleEvent(Event:new("UpdatePos")) + -- Navigation goes through events (ReaderRolling/ReaderPaging both + -- implement onGotoPercent and refresh the view themselves). Calling + -- document:gotoPercent directly crashed KOReader — no such method + -- exists on documents. + self.ui:handleEvent(Event:new("GotoPercent", percentage * 100)) end end