Otherwise the VmData size will keep increasing in multi-threads mode.
Although the increasing VmData size doesn't mean there is enormous
memory leak, it does show that the thread stack is not handled properly
when threads exit.
1. No need to pass the header through string.format()
2. Check for G_battery_logging value inside logBatteryLevel() function
to simply the code in the callers thereof.
When deleting highlights the tables pointing to a highlight's page
number and sequential number within that page must be rebuilt.
The present implementation illustrates the typical use of local
functions in Lua, i.e. for this situation the lexical scope feature of
Lua's local functions is ideally suited.
Memory leak came from the master bitmap that is reused in each reflow. But the bitmap
width and height were not set to zero when bitmap was freed. When the master bitmap was
enlarged in some cases the size of the master bitmap would increase monotonically.
This patch fixes this issue by setting master bitmap width and height to zero at the
beginning of each reflow. And a memeory usage logger is added in koptreader.
Reflowed bitmap should be written to cache before a new reflow is
started because all reflowing processes share the same masterinfo in
libk2pdfopt which contains the data of reflowed bitmap. If a new reflow
is started before a priviously reflowed bitmap is written, the
priviously reflowed bitmap will be corrupted which may cause
segmentation fault when it is written into cache finally.
Cache ttl should not be decreased only when there is no free slot for
new cache but decreased when claiming new cache each time. Otherwise
caches will be freed altogether which obviously is not the purpose of
the cache system. This patch only free the oldest caches and make just
enough free slots for the new one.
1. Comment out re-calculation of parameters to adjust for the case when
the user changed screen orientation, because we force portrait mode on
document close. I left a comment explaining this, so we can uncomment
this code if we choose to not force portrait mode on document close in
thefuture.
2. Don't re-sort the list if the file does not exist.
This predicts the most likely scenario, namely that the user
will choose to delete this stale history entry.
And even if he chooses NOT to delete it, placing a stale entry
to the top of the list contradicts our logic because the
non-existent file was never opened.
When returning from highlight mode there is no need to :goto() to the
current page (and force dummy pre-cache) --- all that is needed is the
redraw of the current page.
The "Last Documents" list is re-sorted on operations that modify it,
such as deleting an entry. But opening/closing a document is also one
such operation and, therefore, requires re-sorting.
The function UniReader:showHighLight() internally handles all cases
where page redraw is necessary. Therefore, there is no need to redraw
the current page (much less to :goto() to it) on return from it.
Prior to introduction of the reader-chooser infrastructure we had a very
useful feature of browsing (and therefore
copying/moving/deleting/renaming/creating) filesystem tree accessing
arbitrary files if the user privilege mode is set to any value higher
than BEGINNER.
This patch restores this functionality by checking the privilege levels
in readerchooser and returning CREReader for any file type if there is
no other reader associated with it (including files with no extension).
The code which determines file type in openFile() is actually unused, so
it can be safely removed. Moreover, if the filename passed to openFile()
happens to have no extension then this would crash openFile(). The
reason this was not noticed before is because no such filename was
passed to openFile() ever, but will be after the next few commits that
are coming...
The command handlers for Home and Alt-Back commands currently perform
exactly the same function (of closing the document) despite the help page
and even the Lua code suggesting otherwise, so it makes sense to merge
them into a single command handler.
The function CREReader:showBookMarks() can have the same logic present
also in its UniReader counterpart, except the goto has to deal with
"xpointers".
Also, I added the number of bookmarks shown in the title of bookmarks
list dialog, just like I did for UniReader:showBookMarks() previously.
Although we are forcing portrait mode upon closing a document and also
start up FileChooser in portrait mode, it is best to not rely on this
fact within the FileChooser itself.
Therefore, I have enhanced FileChooser:choose() method to handle both
landscape and portrait modes by removing the assumption that the global
variables G_width and G_height will maintain the value they had
upon the entry to this function.
This supercedes the fix in PR 616 which actually introduced a memory
corruption bug by using the stale values of G_height/G_width in some
contexts and refreshed value(s) in others.
1. Remove the unnecessary parameters from FileChooser:choose() method.
2. Save frequently used expression G_width - 2*self.margin_H in a local
variable.
3. Replace the calls to fb.bb:getWidth() and fb.bb:getHeight() with the
locally saved copies of G_width and G_height respectively.
1. Move the setting of G_width/G_height inside the function
Screen:setRotationMode()
2. Don't call self:clearCache() twice on closing the document (once is enough).
3. Get rid of UniReader:setRotationMode() method because
Screen:setRotationMode() is enough, as there is nothing reader- or
document-specific in this function.
Displaying a pop-up window for operations like adding a bookmark seems a
bit of an overkill for simple messages like "Bookmark added" or
"Bookmark already exists". Therefore, based on the suggestion by
@dracodoc I have implemented an InfoMessage:drawTopMsg() for this
purpose which just renders the text in the top left corner on a gray
background of auto-calculated appropriate width.
Yes, we already fixed that forcing portrait mode on KPV start, and
document close. However, this is a fix that will prevent the crash if
we don't force portrait. I'm not suggesting that we stop forcing portrait -
I think we all agreed that FileChooser in landscape mode on K3 is not
very usable. But, this might be handy on Touch or KPW (we'll see about that
later), so it should be usable should we need it. To test this, you need to
comment out self:setRotationMode(0) line in UniReader:inputLoop() in
unireader.lua, thus removing forcing of portrait on document close
.
1. In a document with different even/odd bbox, when jumping from odd to even
page, page would be incorrectly positioned.
2. When closing document in fit-to-content-width and 2-column-mode,
and opening it again, the page would not be positioned correctly if you
were not at the beginning of the page when closing.
If you open a document, manually set bbox, then close it and open
another one without bbox, manually set bbox of the previous bbox is
used, which is annoying. This fixes it.