-
Notifications
You must be signed in to change notification settings - Fork 98
Alt-R -> Alt-F -> Alt-C and MANY other things... #475
Conversation
Also, simplify the code a bit by using conditional inside the string concatenation.
Oh, wait, don't merge yet --- I'll make sure the voice version of the message is audible. I fear that it would spell the word "STANDARD" letter by letter i.e. "Es, Tee, Ey, En, Dee..." :) Update: no, all is fine it reads both "STANDARD Reader" and "KOPTReader" correctly... |
Argh.... wait. Another one of those "hardware vs emulator" differences. I forgot that on the real hardware Alt-R is the number 3, so we'll have to choose another key.... I'll put this fix in this PR, don't merge it just yet. |
On Kindle Alt-R is just the number 3, so it is already used in the readers for jumping to a location in the document. Therefore, let us use Alt-F ("F" for "reFlow").
Ok, done, switched to Alt-F, with "F" standing for "reFlow" :) |
Also, there is a slight bug in my implementation: for a per-file setting of the reader choice to be honoured between open/close of different files of the same type one has to restart KPV, but I am working on the fix right now. |
When switching readers we need to ensure that the settings of the old reader are re-initialized, otherwise they will be re-used by the next open of a document of the same type.
The latest commit has the fix for the bug mentioned above, i.e. now the |
While swimming I realized that with a few simple changes we can enhance this implementation to re-open the file automatically instead of just dropping the user back to filechooser. I'll work on this. Also, while at it, I might as well fix/restore the intended functionality of But this PR can be merged without waiting for the above changes as it is complete in itself, imho. |
Can you move it to some other key than Moving it to zoom menu ( |
Ok, I'll move it to another key, no problem. Also, apart from Alt-F change and the need to do re-open, there is another little bug here (switching to koptreader is sometimes TOO persistent, i.e. you can't get back to standard under certain sequence of events --- I'll fix it either today or tomorrow, don't worry :) |
There was a bug whereby if you switched one document to koptreader and then re-opened it with koptreader and closed it and then opened another document of the same type with NO history file or with the history file and NO prior choice of reader (standard or koptreader), then it would open it with koptreader again. Now it works reliably in all circumstances (I hope!)
The bug with "stubborn sticking to koptreader mode" is now fixed. Now, I will deal with the following:
|
This should have been a part of the previous commit.
The debug statements which do not just print something but make calls to other functions and perform calculations should be uncommented only during debugging.
Removing this code allows us to get rid of alt_getopt.lua module altogether. And all that code is unused anyway, i.e. we can't pass passwords via openFile() and we ignore the global variable globalgamma, etc etc.
This initialization was accidentally left uncommented (it was commented during testing, but for some reason I uncommented it when I made a commit :)
We should leave the F key for things related to multi-column modes, so the next natural choice is Alt-C, with "C" standing for "Change reader".
Ok, I think there is enough for this PR. The code to re-open on Alt-C should go into the next PR as it is logically independent. |
No, no, no, wait --- don't merge this PR yet.... |
I found yet another bug, seems UNRELATED to my changes, but to make 100% sure that it is unrelated I need to test it a bit more. Leave it until tomorrow when I have tested and reported one way or the other. |
Phewww.... that's a relief --- the crash has nothing to do with my changes. Namely, it is just a crash coming from k2pdfopt internals on certain pages of some complex PDF files. I can supply the files, of course, but they are not easily reproducible --- it was just bad luck that I happened to open that file first when testing this PR on the real Kindle :) |
Actually, out of curiousity, I am going to debug this crash myself, let's see what I find. So perhaps leave this PR as is and wait if I can put the fix for this crash into this PR as well.... |
Here is the stacktrace:
I'll now enable blitbuffer boundary checking and see if it catches it... |
Hmm, blitbuffer debug checking did not catch it, but I used the "old-fashioned" way, put a printf() at line 240 of blitbuffer.c like this:
and, lo and behold:
But
So, I put another printf right after the above assignment:
and got this result:
So, something has passed
NB. Reproducible in the |
Actually, although this is unrelated to the present PR, I still think I am the one to blame, because if I restart KPV and re-open the same PDF file on the same page using koptreader then it does not crash. So, it is only when we are staying within KPV and re-opening it it crashes. This means that something is missing from the way I close it in the command handler like this:
Plus, of course, the usual cleanup done in the the |
And, btw, with DjVu files it will also coredump in the same function a few lines earlier at the code |
The crash is actually coming from this line in
for some reason the |
Need we have a reflow flag in pagehash? So that when switched to koptreader the blitbuffer is refreshed. |
That |
Oh, you are right --- something impossible happens, i.e. in Update: clearCache is called for DJVUReader but somehow that pagehash entry is re-used by KOPTReader. How can that be? |
Yes, adding an 'X' at the tail of pagehash expression in |
Also, the problem is asymmetric, i.e. it only happens in the switch from standard to koptreader, but NOT when switching from koptreader to standard. If the solution was to have a different pagehash expression between different readers then the problem would also happen when switching from koptreader to standard, right? Actually, putting some debug print()s in |
This is getting very interesting. Here is the state of both DjVu and KOPT caches at the time of closing the DjVu document, just before clearCache() call in inputLoop():
As you see KOPT cache is duplicating DJVU cache. I am dumping them using the proper object, of course, i.e. like this:
and the function dumpCache() is defined to be:
I am trying to find out why |
It turns out that ALL readers share the cache and this is seen on normal close of the document, i.e. NOT using the new
So, when closing DjVu document, just before clearCache() all other reader's caches contain the same pagehash entries except their |
Looks like a bug in LuaJIT, i.e. if your object has two fields (a table and a number) and you create two derived objects, then the table field they share, but the number field each instance gets his own copy. I will try to reproduce it with a small test.lua program. Well, we have the solution already anyway --- to add something specific to KOPTReader (like a letter |
Ok, it is not a bug, it is the way we manage blitbuffer metatable in |
@tigran123 I'm now implementing the file association version of switching between Standard reader and Koptreader. So please don't merge this PR and wait for several hours and see which way is more appropriate. |
Well, the first part of my implementation is already in the master. But it can be reverted, of course, if your implementation is better. Anyway I'll put the crash fix into this PR now. And then we shall compare the two approaches "side by side", so to speak :) |
Our current tile cache architecture is such that the "cache" table is actually shared among all reader objects. This is not normally noticeable because different objects handle different file types and so they never attempt to re-use each other's cache. However the DJVUReader, PDFReader and KOPTReader handle the same file types and cache re-use can lead to a crash. The fix is to make the pagehash formula used by KOPTReader uniquely different from the one used by DJVUReader and PDFReader.
@tigran123 Thanks. I'm going to do my work now. |
@chrox Ok, and I promise to review it in an unbiased way. |
Btw, this PR cannot be automatically merged in ANY case, so I'll extract some bits into a separate PR which can be merged regardless of our choice of the way to switch between standard/koptreader. E.g. removal of unneeded code from reader.lua. |
Before I go I decided to put my implementation into a separate PR with a single compact commit so we can truly compare the code of two mergable PRs "side by side" (except the bit that is already in the master, but your PR would be undoing it so still we can do the comparison). The new PR is #479 so I am closing this one. |
@tigran123 , very interesting bug hunting process :) Now you know how to fix the bug :) Following code can be an alternative way to fix the bug: PDFReader = UniReader:new{
cache = {}
} This make sure a specific reader uses it's own cache instead of the cache shared by all readers. BTW: the cache system is designed and implemented by @hwhw , he designed and implemented all the basic layouts of KPV, including the new_ui_branch. |
Yep, I'm probably the one to blame. I guess emptying the cache is the way |
Also, simplify the code a bit by using conditional inside the string concatenation.