mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
credocument: deal with loadDocument() failures (#3570)
cre:loadDocument() may fail in recognizing the document format, and koreader would previously keep calling other methods on it, which would make crengine segfaults. We now check loadDocument success at the various places it is called, and try to deal the best way we can when it fails.
This commit is contained in:
@@ -109,6 +109,11 @@ function CreDocument:init()
|
||||
-- set fallback font face
|
||||
self._document:setStringProperty("crengine.font.fallback.face", self.fallback_font)
|
||||
|
||||
-- We would have liked to call self._document:loadDocument(self.file)
|
||||
-- here, to detect early if file is a supported document, but we
|
||||
-- need to delay it till after some crengine settings are set for a
|
||||
-- consistent behaviour.
|
||||
|
||||
self.is_open = true
|
||||
self.info.has_pages = false
|
||||
self:_readMetadata()
|
||||
@@ -117,9 +122,11 @@ end
|
||||
|
||||
function CreDocument:loadDocument()
|
||||
if not self._loaded then
|
||||
self._document:loadDocument(self.file)
|
||||
self._loaded = true
|
||||
if self._document:loadDocument(self.file) then
|
||||
self._loaded = true
|
||||
end
|
||||
end
|
||||
return self._loaded
|
||||
end
|
||||
|
||||
function CreDocument:render()
|
||||
@@ -160,7 +167,9 @@ end
|
||||
|
||||
function CreDocument:getCoverPageImage()
|
||||
-- don't need to render document in order to get cover image
|
||||
self:loadDocument()
|
||||
if not self:loadDocument() then
|
||||
return nil -- not recognized by crengine
|
||||
end
|
||||
local data, size = self._document:getCoverPageImageData()
|
||||
if data and size then
|
||||
local Mupdf = require("ffi/mupdf")
|
||||
|
||||
Reference in New Issue
Block a user