ReaderRolling: Guard against races between scheduled tasks and CloseDocument (#10934)

Fix #10932

---------

Co-authored-by: Frans de Jonge <fransdejonge@gmail.com>
reviewable/pr10938/r1
NiLuJe 9 months ago committed by GitHub
parent cafe565ade
commit e5535a3a3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -78,6 +78,10 @@ local ReaderRolling = InputContainer:extend{
RELOADING_DOCUMENT = 4, RELOADING_DOCUMENT = 4,
DO_RELOAD_DOCUMENT = 5, DO_RELOAD_DOCUMENT = 5,
}, },
mark_func = nil,
unmark_func = nil,
_stepRerenderingAutomation = nil,
} }
function ReaderRolling:init() function ReaderRolling:init()
@ -313,6 +317,16 @@ end
-- we cannot do it in onSaveSettings() because getLastPercent() uses self.ui.document -- we cannot do it in onSaveSettings() because getLastPercent() uses self.ui.document
function ReaderRolling:onCloseDocument() function ReaderRolling:onCloseDocument()
self:tearDownRerenderingAutomation() self:tearDownRerenderingAutomation()
-- Unschedule anything that might still somehow be...
if self.mark_func then
UIManager:unschedule(self.mark_func)
end
if self.unmark_func then
UIManager:unschedule(self.unmark_func)
end
UIManager:unschedule(self.onCheckDomStyleCoherence)
UIManager:unschedule(self.onUpdatePos)
self.current_header_height = nil -- show unload progress bar at top self.current_header_height = nil -- show unload progress bar at top
self.ui.doc_settings:saveSetting("percent_finished", self:getLastPercent()) self.ui.doc_settings:saveSetting("percent_finished", self:getLastPercent())
@ -349,7 +363,7 @@ function ReaderRolling:onCheckDomStyleCoherence()
ok_callback = function() ok_callback = function()
-- Allow for ConfirmBox to be closed before showing -- Allow for ConfirmBox to be closed before showing
-- "Opening file" InfoMessage -- "Opening file" InfoMessage
UIManager:scheduleIn(0.5, function () UIManager:scheduleIn(0.5, function()
-- And check we haven't quit reader in these 0.5s -- And check we haven't quit reader in these 0.5s
if self.ui.document then if self.ui.document then
self.ui:reloadDocument() self.ui:reloadDocument()
@ -801,7 +815,7 @@ end
function ReaderRolling:onGotoXPointer(xp, marker_xp) function ReaderRolling:onGotoXPointer(xp, marker_xp)
if self.mark_func then if self.mark_func then
-- unschedule previous marker as it's no more accurate -- Unschedule previous marker as it's no longer accurate.
UIManager:unschedule(self.mark_func) UIManager:unschedule(self.mark_func)
self.mark_func = nil self.mark_func = nil
end end
@ -1005,9 +1019,7 @@ function ReaderRolling:onBatchedUpdateDone()
self.batched_update_count = 0 self.batched_update_count = 0
-- Be sure any Notification gets a chance to be painted before -- Be sure any Notification gets a chance to be painted before
-- a blocking rerendering -- a blocking rerendering
UIManager:nextTick(function() UIManager:nextTick(self.onUpdatePos, self)
self:onUpdatePos()
end)
end end
end end
@ -1036,7 +1048,10 @@ function ReaderRolling:onUpdatePos(force)
-- Calling this now ensures the re-rendering is done by crengine -- Calling this now ensures the re-rendering is done by crengine
-- so updatePos() has good info and can reposition -- so updatePos() has good info and can reposition
-- the previous xpointer accurately: -- the previous xpointer accurately:
self.ui.document:getCurrentPos() if self.ui.document then
-- This can be racy with CloseDocument, as it's scheduled by onBatchedUpdateDone, guard it
self.ui.document:getCurrentPos()
end
-- Otherwise, _readMetadata() would do that, but the positioning -- Otherwise, _readMetadata() would do that, but the positioning
-- would not work as expected, for some reason (it worked -- would not work as expected, for some reason (it worked
@ -1087,9 +1102,7 @@ function ReaderRolling:updatePos(force)
-- Allow for the new rendering to be shown before possibly showing -- Allow for the new rendering to be shown before possibly showing
-- the "Styles have changed..." ConfirmBox so the user can decide -- the "Styles have changed..." ConfirmBox so the user can decide
-- if it is really needed -- if it is really needed
UIManager:scheduleIn(0.1, function () UIManager:scheduleIn(0.1, self.onCheckDomStyleCoherence, self)
self:onCheckDomStyleCoherence()
end)
end end
function ReaderRolling:onChangeViewMode() function ReaderRolling:onChangeViewMode()
@ -1619,7 +1632,7 @@ Note that %1 (out of %2) xpaths from your bookmarks and highlights have been nor
ok_text = _("Upgrade now"), ok_text = _("Upgrade now"),
ok_callback = function() ok_callback = function()
-- Allow for ConfirmBox to be closed before migrating -- Allow for ConfirmBox to be closed before migrating
UIManager:scheduleIn(0.5, function () UIManager:scheduleIn(0.5, function()
-- And check we haven't quit reader in these 0.5s -- And check we haven't quit reader in these 0.5s
if self.ui.document then if self.ui.document then
-- We'd rather not have any painting between the upgrade -- We'd rather not have any painting between the upgrade

Loading…
Cancel
Save