From bee2a605f111319b1eb8b2a269a7fb956d251488 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sat, 22 May 2021 04:46:41 +0200 Subject: [PATCH] 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. --- frontend/apps/reader/modules/readerstatus.lua | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/frontend/apps/reader/modules/readerstatus.lua b/frontend/apps/reader/modules/readerstatus.lua index b83b522c9..d1dc937fa 100644 --- a/frontend/apps/reader/modules/readerstatus.lua +++ b/frontend/apps/reader/modules/readerstatus.lua @@ -144,8 +144,11 @@ function ReaderStatus:onEndOfBook() } UIManager:show(info) UIManager:forceRePaint() - self:openNextFile(self.document.file) 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 UIManager:show(InfoMessage:new{ 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 self.ui:handleEvent(Event:new("GoToBeginning")) elseif settings == "file_browser" then - self:openFileBrowser() + -- Ditto + UIManager:nextTick(function() + self:openFileBrowser() + end) elseif settings == "mark_read" then self:onMarkBook(true) UIManager:show(InfoMessage:new{ @@ -162,10 +168,16 @@ function ReaderStatus:onEndOfBook() timeout = 3 }) elseif settings == "book_status_file_browser" then - local before_show_callback = function() self:openFileBrowser() end - self:onShowBookStatus(before_show_callback) + -- Ditto + UIManager:nextTick(function() + local before_show_callback = function() self:openFileBrowser() end + self:onShowBookStatus(before_show_callback) + end) elseif settings == "delete_file" then - self:deleteFile(self.document.file, true) + -- Ditto + UIManager:nextTick(function() + self:deleteFile(self.document.file, true) + end) end end @@ -175,7 +187,6 @@ function ReaderStatus:openFileBrowser() if not FileManager.instance then self.ui:showFileManager() end - self.document = nil end function ReaderStatus:openNextFile(next_file)