Skip to content

Fix Location Stack Issues - #13607

Merged
yparitcher merged 3 commits into
koreader:masterfrom
yparitcher:stack
Apr 18, 2025
Merged

yparitcher merged 3 commits into
koreader:masterfrom
yparitcher:stack

Conversation

@yparitcher

@yparitcher yparitcher commented Apr 16, 2025 •

Copy link
Copy Markdown
Member

Closes: #13570
Closes: #12869
Closes: #11989
Supersedes: #13560

@jonnyl2

The crash is fixed by the second commit (reproduced and tested), the nil check is enough, please confirm.

The issues in #13570 are fixed by the second commit, i reproduced and tested with the first issue there, but it should fix the second also, please confirm


This change is Reviewable

it can pe passed a nil / empty table if the location stack is empty, return early in this case.

Fixes: koreader#12869
@jonnyl2

jonnyl2 commented Apr 16, 2025

Copy link
Copy Markdown
Contributor

Indeed, I confirm I couldn't reproduce the crashes reported in #12869 and the 2 issues mentioned in #13570 after applying these fixes. Thank you!

However, on the topic of location stacks there is another issue that's been bugging me that appears to affect all engines/view modes equally, and it happens to be my typical use case for the location stacks (and I imagine most other users' as well):

Let's say I'm reading something at page 50, then skip to the back of the book to the notes (say page 270), then go back to page 50, continue reading, and then I want to go forward to the notes again. This works as long as I stay on page 50, but as soon as I turn the page forward (51) or backward (49), then Forward to next location doesn't take me to page 270 but to page 50! I have to go forward twice. This doesn't make any sense IMO. It is my understanding that regular page turns/ scrolls should not affect the Back to previous location and Forward to next location location stacks at all, only the more granular Back location stack. Or is this incorrect?

@yparitcher

Copy link
Copy Markdown
Member Author

Hard to explain in words, but a visualization might help.
Current Page 20 Previous locations . Forward locations .

  1. Goto page 40
    C 40 P 20 F .
  2. Goto page 60
    C 60 P 20,40 F .
  3. Back to previous
    C 40 P 20 F 60,40

Being as Page 40 is on the Forward stack if you now change to next page 41, Back is 20 but Forward is 40.
C 41 P 20 F 60,40

This allows for:

4A. Back to previous
C 20 P . F 60,40,20

So if we go forward now, we get to 40 (current page is transparently skipped). This is only possible because 40 was put on the forward stack in step 3.

But we also get:
4B. Forward to next
C 40 P 20,40, F 60
4C. Goto page 80 (or follow a link)
C 80 P 20,41 F .

They way to fix this is to complicate the location stack implementation and add a 3rd stack that only can have one entry Current stack, and lets play the steps again:

C 20 P . F . C .

  1. Goto page 40
    C 40 P 20 F . C .
  2. Goto page 60
    C 60 P 20,40 F . C .
  3. Back to previous
    C 40 P 20 F 60 C 40

Even if you now change to next page 41,
C 41 P 20 F 60 C 40

4A. Back to previous
C 20 P . F 60,40 C 20
4B. Forward to next
C 60 P 20,40 F . C 60
4C. Goto page 80 (or follow a link)
C 80 P 20,(40?),41 F . C .
(Do we add page 40 to previous stack in 4C?)

This works but requires more overhead and calculations compared to the current simpler approach (and i am not sure it won't break other workflows / code), so am not going to PR for now, but open to comments / ideas

@yparitcher

Copy link
Copy Markdown
Member Author

Sorry for bad formatting due to mobile

@jonnyl2

jonnyl2 commented Apr 17, 2025 •

Copy link
Copy Markdown
Contributor

Thanks @yparitcher - I put the steps in table below for easier comparison. (I changed the ordering in the stacks so that the numbers are in the order they would come up if the action is called by the user, from LTR):

Status quo:

Current page Previous Loc stack Forward Loc stack User Action
20 -- -- 1. Goto 40
40 20 -- 2. Goto 60
60 40; 20 -- 3. Back to Previous Loc
40 20 40; 60 4. Page turn +1
41 20 40; 60 4A. Back to Previous Loc
20 -- 20; 40; 60
41 20 40; 60 4B. Forward to Next Loc
40 40; 20 60
41 20 40; 60 4C. Goto 80
80 41; 20 --

How I would expect the stacks to work (without needing a 3rd stack):

Current Page Previous Loc stack Forward Loc stack User Action
20 -- -- 1. Goto 40
40 20 -- 2. Goto 60
60 40; 20 -- 3. Back to Previous Loc
40 20 60 4.Page turn +1
41 20 60 4A. Back to Previous Loc
20 -- 41; 60
41 20 60 4B. Forward to Next Loc
40 41; 20 --
41 20 60 4C. Goto 80
80 41; 20 60

Of course it's possible that I'm missing something, and I'm happy to move the discussion elsewhere (e.g., back to issue #13570, or a new issue). The most important thing is that the crashes are being fixed with this PR :)

@yparitcher

Copy link
Copy Markdown
Member Author

I edited / fixed your status quo table.

@yparitcher

Copy link
Copy Markdown
Member Author

Currently after step 3, if page 40 is not on the current location stack it breaks step 4a.
We want page 40, not 41 to be on the stack (imagine you clicked a link and followed the paragraph to the next page and click a second link, we want the stack progression to contain the first page, where the paragraph starts)

@jonnyl2

jonnyl2 commented Apr 17, 2025

Copy link
Copy Markdown
Contributor

I edited / fixed your status quo table.

I also corrected the bottom table for 4C

@yparitcher

Copy link
Copy Markdown
Member Author

For more details and motovation see #10228 where i implemented the forward stack

@jonnyl2

jonnyl2 commented Apr 17, 2025

Copy link
Copy Markdown
Contributor

I edited / fixed your status quo table.

I think there is a misunderstanding in the way to read the table. I just tested it again and the current location is only added to the fwd stack after the page turn. The 3rd column is prior to the action in column 4.

@yparitcher

Copy link
Copy Markdown
Member Author

table.insert(self.forward_location_stack, saved_location)

We add the current location to the forward stack when going back. So after step 3. We have 40 & 60 on the forward stack.

@jonnyl2

jonnyl2 commented Apr 18, 2025

Copy link
Copy Markdown
Contributor

OK, I see what you mean. I built the table from a UX perspective; with regard to which locations the Reader UI jumps to when the back/forward actions are triggered, not with what is happening behind the scenes not discernible by the user. The Back/Forward link functions bypass the page if it is the same as current page the reader is on, that's why it appears that it is only added on the next step. But I can see where the confusion came from and could have made my intent clearer.

Anyway, I don't want to unneccesarily delay this PR. I'd like to study the original PR you linked to and your comments and suggestions for an alternative approach, and then get back with a better informed opinion.

@NiLuJe NiLuJe added this to the 2025.05 milestone Apr 18, 2025
@NiLuJe NiLuJe added the bug label Apr 18, 2025
@yparitcher
yparitcher merged commit 8556d77 into koreader:master Apr 18, 2025
@yparitcher
yparitcher deleted the stack branch April 18, 2025 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

4 participants