A bunch of fixes#7702
Conversation
DocumentRegistry just decreases a ref, it doesn't close anything. Plug the same Document leak in a few other places, and document this.
As discussed in koreader#7646, regression since koreader#6322
Namely, instead of making it lower priority than readerhighlight and hoping for the best, make it higher priority, as it should (ReaderFooter itself is *above* Reader, after all), with a sane set of fallthroughs: * No footer * No hold-to-skim * Held outside the footer (but inside the footer tap zone) This made the crap workaround from koreader#7466 unnecessary, and actually fixes the behavior in PDFs (because readerhighlight will match the *physical* page, which may include off-screen content) and ePubs w/r eclaim bar height (in which case, there's actual content behind the footer that readerhighlight could have matched on). Fix koreader#7697
| end | ||
| UIManager:close(self.file_dialog) | ||
| DocumentRegistry:closeDocument(file) | ||
| document:close() |
There was a problem hiding this comment.
No issue if we're viewing the cover via History of the same currently opened document in Reader?
(I see that this is not the case, but I would have expected DocumentRegistry:closeDocument() to itself closes the doc when refs becomes 0 :/)
There was a problem hiding this comment.
Oh, ok, Document:close() does not really close it if refs is not 0 :) So, the cleverness it there instead of here, but same thing in the end.
There was a problem hiding this comment.
Hopefully DocumentRegistry does its job and returns the cached instance ^^.
There was a problem hiding this comment.
Document:close only actually tears down the instance if the refcount drops to zero, so, provided everything works out, it's safe.
There was a problem hiding this comment.
(Whee, missed the second comment ^^).
Yeah, it's more of a case of non-intuitive naming & lack of documentation ;).
|
Mhhh, not so sure about the ReaderFooter commit. That means we'd have a hard time doing a word lookup on the last line of the page... My reasoning for these overrides at the time in #5789. |
|
Although I see that if you want "hold on footer to skim" to work as written on the tin (even if there's a word below), it has to be higher priority than ReaderHighlight. Anyway, nothing critical among the fixes of this PR, which could be fine for 2021.06. |
That works just fine now that we have an accurate Geom, which allows making the effective hold zone the footer itself, not the tap zone, meaning any hold outside the footer gets passed to ReaderHighlight. (We couldn't do that originally because the footer's dimen was broken as all hell). |
I actually have no idea what the default is, and no preference about that myself. I probably usually have it disabled in fact, as I had to enable it to test this ;p. |
e.g., even an absolute worst-case scenario like that (thanks to reclaim height) works: |
b6beb18 to
834ad0e
Compare
a40a0cc to
e1833ea
Compare
|
Last minute but tagged 2021.06? |
|
Little bit of discussion above, possibly a bit too risky, was changed from 2021.05 to 2021.06. |
|
Alright, in that case I won't look at this PR (today, anyway). |
|
(Also, I broke my most favorite test in the world and didn't have an emu build ready to fix it ^^). EDIT: Fixed it. |
FFI finalizers can fire in unspecified orders, but for MuPDF, we need to ensure that the context is the *very* last thing that get destroyed. As such, we need to make sure we close open documents properly on our end, first. This prevents potential crashes while switchign to USBMS inside an open document handled by MuPDF. Fix koreader#7428
And go through one-time-migration to ensure the settings are properly filled. Also, disable hold-to-skim by default.
Tests: Update the ffi.metatype wrapper (Better idea: move to busted master).
We're now more careful about this, so, I suppose weird timings may mean we might be trying to access a nil here. Fix koreader#7706 Guard a few other similar constructs
It's somewhat non-trivial, and has been unmaintained for years.
* Tear down FM instances properly * Don't manhandle ReaderUI too much, and document when the tests do actively broken shit, like bypassing safeties to open two // ReaderUI instances.
|
Okay, I should be done playing with the tests now ;p. |
Expanding on koreader#7682 ffi/input, loaded by the Device singleton, also needs to know that in order to setup the proper input backend for SDL2. Requires koreader/koreader-base#1372 because that's where the machinery for those checks live.
Do a proper reset to defaults before each test without actually poking at the defaults table itself.
poire-z
left a comment
There was a problem hiding this comment.
Fine with me (after the base bump).
(Wonder if the added self.ui and self.ui.document/doc_settings might hide future bugs :)
|
Use http://koreader.rocks/doc/modules/dbg.html#Dbg.dassert then. ;-) |
|
@poire-z Could you comment on the relevant line? I'm not sure what you're referring to at a glance. |
| local ReaderUI = require("apps/reader/readerui") | ||
| local ui = ReaderUI:_getRunningInstance() | ||
| if ui then | ||
| if ui and ui.document then |
There was a problem hiding this comment.
Thanks. So basically, something like:
| if ui and ui.document then | |
| dbg.dassert(ui ~= nil) | |
| if ui and ui.document then |
There was a problem hiding this comment.
How can UI be nil when the screensaver is activated? That doesn't seem to make sense.
There was a problem hiding this comment.
You won't have a ReaderUI instance in the FM, for example ;).
| function FileManagerHistory:onMenuHold(item) | ||
| local readerui_instance = require("apps/reader/readerui"):_getRunningInstance() | ||
| local currently_opened_file = readerui_instance and readerui_instance.document.file | ||
| local currently_opened_file = readerui_instance and readerui_instance.document and readerui_instance.document.file |
| local ReaderUI = require("apps/reader/readerui") | ||
| local ui = ReaderUI:_getRunningInstance() | ||
| if ui then | ||
| if ui and ui.doc_settings then |
|
The thing is that we witness edge/evil cases where some stuff might happen (via Dispatcher only?) while ReaderUI is half being born or half dying. |
FWIW, those are all the instances where the ReaderUI instance pointer is accessed from outside (as opposed to inherited via an instance-time ui/dialog/parent/show_parent pointer). (All of it is in 161a7b1) The reasoning being stuff that inherits it usually has a clearer lifecycle, because it's instantiated and torn-down with that same ReaderUI instance (e.g., |
|
I can certainly wrap the extra hashkey checks in a debug assert if we're more comfortable with that, though? |
|
OK, I'm convinced :)
No need I think, if it ends up being only History and ScreenSaver, that can obviously be used from FileManager. |
NiLuJe
left a comment
There was a problem hiding this comment.
Reviewed 5 of 5 files at r1, 3 of 4 files at r2, 18 of 19 files at r3, 3 of 3 files at r4, 1 of 1 files at r5.
Dismissed @poire-z from 2 discussions.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @poire-z)
frontend/apps/filemanager/filemanagerhistory.lua, line 47 at r4 (raw file):
Previously, poire-z wrote…
Or this.
Done.
frontend/ui/screensaver.lua, line 306 at r4 (raw file):
Previously, poire-z wrote…
Or that.
Done.
|
Got these WARN on my first launch after updating this morning: Don't remember what I did (gestures, taps?), but I can't reproduce... OK. Trying that again, I get them both again (some View full size covers from History) - plus a crash :/ : |
|
Ah, that might explain all the gesture weirdness we've seen lately... I'll see what I can suss out (because that works fine from Menus, FWIW) :}. |
|
Okay, the warning is normal: if you view the cover of the currently open'ed book, that's a "cache" hit in DocumentRegistry (so, refcnt == 2 on open, and 1 on close => warn). The crash is sneakier, it's because the engine's close method is called before the refcnt check (since it's handled by the base class's close), and it may destroy critical engine-specific data (here, the buffer and the call cache). |
|
Shouldn't be koreader/frontend/apps/reader/modules/readerfooter.lua Lines 592 to 605 in bfda4bf Now, if the progress bar is disabled, horizontal_group includes progress_bar with zero width. |
|
@hius07: Logic should be unchanged (compared to before the PR). The fact that the layout code explicit handles (I mean, feel free to experiment if you want, but unless you can actively break it, meh' ;)). |
|
May I ask one more question. What is the difference in getting margins here koreader/frontend/apps/reader/modules/readerfooter.lua Lines 2062 to 2063 in bfda4bf and here koreader/frontend/apps/reader/modules/readerfooter.lua Lines 2075 to 2078 in bfda4bf |
|
I mean, can we always ask for koreader/frontend/apps/reader/modules/readerfooter.lua Lines 2282 to 2288 in bfda4bf |
|
The 2nd piece of code above is in For :onSetPageHorizMargins(), ReaderFooter and ReaderTypeset got them. ReaderTypeset is the one that will give it to crengine. And it looks that with the order of modules, ReaderFooter will get the even before ReaderTypeset - so using |

Some of 'em rather nasty (hi, crazy Document leak!).
This change is