From 9a7450ea5f02407b288e922ee4bac39588b485ca Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sat, 11 Sep 2021 20:17:18 +0200 Subject: [PATCH] Statistics: Guard against ReaderView's state.page being nil For... whatever reason? I can't really see that happening, but, oh, well. Screensaver already guards against it, so, who knows. Fix #8201 --- plugins/statistics.koplugin/main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index 45ab786b9..130ccdafc 100644 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -1313,7 +1313,7 @@ function ReaderStatistics:getCurrentStat(id_book) self.data.pages = self.view.document:getPageCount() total_time_book = tonumber(total_time_book) total_read_pages = tonumber(total_read_pages) - local time_to_read = (self.data.pages - self.view.state.page) * self.avg_time + local time_to_read = self.view.state.page and ((self.data.pages - self.view.state.page) * self.avg_time) or 0 local estimate_days_to_read = math.ceil(time_to_read/(book_read_time/tonumber(total_days))) local estimate_end_of_read_date = os.date("%Y-%m-%d", tonumber(now_ts + estimate_days_to_read * 86400)) local estimates_valid = time_to_read > 0 -- above values could be 'nan' and 'nil'