ReaderStatus: Don't crash in EndOfDocument actions that *immediately* destroy the ReaderUI instance. (#7733)

This is handled in an Event handler, but we have zero guarantee that
we're actually the *final* Event sent to the Document, and other Events
usually kinda need the Document instance to still be alive ;).

Delay action until the next tick to avoid potential crashes.
pull/7734/head
NiLuJe 3 years ago committed by GitHub
parent c05b1a4ee4
commit bee2a605f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -144,8 +144,11 @@ function ReaderStatus:onEndOfBook()
} }
UIManager:show(info) UIManager:show(info)
UIManager:forceRePaint() UIManager:forceRePaint()
self:openNextFile(self.document.file)
UIManager:close(info) UIManager:close(info)
-- Delay until the next tick, as this will destroy the Document instance, but we may not be the final Event caught by said Document...
UIManager:nextTick(function()
self:openNextFile(self.document.file)
end)
else else
UIManager:show(InfoMessage:new{ UIManager:show(InfoMessage:new{
text = _("Could not open next file. Sort by last read date does not support this feature."), text = _("Could not open next file. Sort by last read date does not support this feature."),
@ -154,7 +157,10 @@ function ReaderStatus:onEndOfBook()
elseif settings == "goto_beginning" then elseif settings == "goto_beginning" then
self.ui:handleEvent(Event:new("GoToBeginning")) self.ui:handleEvent(Event:new("GoToBeginning"))
elseif settings == "file_browser" then elseif settings == "file_browser" then
self:openFileBrowser() -- Ditto
UIManager:nextTick(function()
self:openFileBrowser()
end)
elseif settings == "mark_read" then elseif settings == "mark_read" then
self:onMarkBook(true) self:onMarkBook(true)
UIManager:show(InfoMessage:new{ UIManager:show(InfoMessage:new{
@ -162,10 +168,16 @@ function ReaderStatus:onEndOfBook()
timeout = 3 timeout = 3
}) })
elseif settings == "book_status_file_browser" then elseif settings == "book_status_file_browser" then
local before_show_callback = function() self:openFileBrowser() end -- Ditto
self:onShowBookStatus(before_show_callback) UIManager:nextTick(function()
local before_show_callback = function() self:openFileBrowser() end
self:onShowBookStatus(before_show_callback)
end)
elseif settings == "delete_file" then elseif settings == "delete_file" then
self:deleteFile(self.document.file, true) -- Ditto
UIManager:nextTick(function()
self:deleteFile(self.document.file, true)
end)
end end
end end
@ -175,7 +187,6 @@ function ReaderStatus:openFileBrowser()
if not FileManager.instance then if not FileManager.instance then
self.ui:showFileManager() self.ui:showFileManager()
end end
self.document = nil
end end
function ReaderStatus:openNextFile(next_file) function ReaderStatus:openNextFile(next_file)

Loading…
Cancel
Save