mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Fix potential crash when clearing hold highlight (#3241)
A delayed clear() could reset hold_pos while a onHold/onHoldPan/ onHoldRelease is in progress, resulting in hold_pos becoming nil and a crash.
This commit is contained in:
@@ -110,7 +110,23 @@ function ReaderHighlight:genHighlightDrawerMenu()
|
||||
}
|
||||
end
|
||||
|
||||
function ReaderHighlight:clear()
|
||||
-- Returns a unique id, that can be provided on delayed call to :clear(id)
|
||||
-- to ensure current highlight has not already been cleared, and that we
|
||||
-- are not going to clear a new highlight
|
||||
function ReaderHighlight:getClearId()
|
||||
self.clear_id = TimeVal.now() -- can act as a unique id
|
||||
return self.clear_id
|
||||
end
|
||||
|
||||
function ReaderHighlight:clear(clear_id)
|
||||
if clear_id then -- should be provided by delayed call to clear()
|
||||
if clear_id ~= self.clear_id then
|
||||
-- if clear_id is no more valid, highlight has already been
|
||||
-- cleared since this clear_id was given
|
||||
return
|
||||
end
|
||||
end
|
||||
self.clear_id = nil -- invalidate id
|
||||
if self.ui.document.info.has_pages then
|
||||
self.view.highlight.temp = {}
|
||||
else
|
||||
@@ -223,6 +239,7 @@ end
|
||||
function ReaderHighlight:onHold(arg, ges)
|
||||
-- disable hold gesture if highlighting is disabled
|
||||
if self.view.highlight.disabled then return true end
|
||||
self:clear() -- clear previous highlight (delayed clear may not have done it yet)
|
||||
self.hold_pos = self.view:screenToPageTransform(ges.pos)
|
||||
logger.dbg("hold position in page", self.hold_pos)
|
||||
if not self.hold_pos then
|
||||
|
||||
Reference in New Issue
Block a user