Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8303680 Virtual Flow freezes after calling scrollTo and scrollPixels in succession #1052

Closed

Conversation

FlorianKirmaier
Copy link
Member

@FlorianKirmaier FlorianKirmaier commented Mar 6, 2023

Possible fix for VirtualFlow freeze.

I encountered the problem when experimenting with VirtualFlow.

Guess @johanvos should take a look.
All tests are still green, so with some luck, this doesn't break anything but fixes some known and unknown bugs.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed (2 reviews required, with at least 1 Reviewer, 1 Author)

Issue

  • JDK-8303680: Virtual Flow freezes after calling scrollTo and scrollPixels in succession

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx pull/1052/head:pull/1052
$ git checkout pull/1052

Update a local copy of the PR:
$ git checkout pull/1052
$ git pull https://git.openjdk.org/jfx pull/1052/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1052

View PR using the GUI difftool:
$ git pr show -t 1052

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1052.diff

Possible fix for VirtualFlow freeze
updated test name
@bridgekeeper
Copy link

bridgekeeper bot commented Mar 6, 2023

👋 Welcome back fkirmaier! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Ready for review label Mar 6, 2023
@mlbridge
Copy link

mlbridge bot commented Mar 6, 2023

Webrevs

@FlorianKirmaier FlorianKirmaier changed the title JDK-8303680 VirtualFlow freeze 8303680 VirtualFlow freeze Mar 6, 2023
@kevinrushforth
Copy link
Member

You will need to modify the title of this PR to match the JBS bug title (which I slightly modified to change "crashed" to "freezes" to better reflect the problem).

/reviewers 2

@openjdk
Copy link

openjdk bot commented Mar 6, 2023

@kevinrushforth
The total number of required reviews for this PR (including the jcheck configuration and the last /reviewers command) is now set to 2 (with at least 1 Reviewer, 1 Author).

@FlorianKirmaier FlorianKirmaier changed the title 8303680 VirtualFlow freeze 8303680 Virtual Flow freezes after calling scrollTo and scrollPixels in succession Mar 6, 2023

// scroll to 50 and scroll 1 pixel
vf.scrollTo(50);
vf.scrollPixels(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a rather artificial test.
is it possible to reproduce the condition using control's public APIs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the public API of VirtualFlow. I don't know whether it's possible with the API of the Control - But the API of the VirtualFlow should be stable too, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it is public API. One can't get directly to it, but it is possible to subclass the ListView and use the protected getVirtualFlow() method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have many tests that access VirtualFlow, so that seems ok.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be possible to update the JBS ticket with a valid code example?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be very helpful.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't notice that I did upload the wrong file.
I've now uploaded the correct test application!

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let others do the formal review of this, but I would like to see an evaluation of what the root cause is, why this is the right fix, and whether there are any side effects. As it is, all I see is a removed line with no explanation of the problem or the solution.


// scroll to 50 and scroll 1 pixel
vf.scrollTo(50);
vf.scrollPixels(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have many tests that access VirtualFlow, so that seems ok.

@@ -1715,7 +1715,6 @@ public double scrollPixels(final double delta) {

// Finally, update the scroll bars
updateScrollBarsAndCells(false);
lastPosition = getPosition();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a formal review -- I'll let Andy and Johan do that -- but can you explain why this is the right fix? Presumably there was at least some reasoning behind updating lastPosition. Are there any side effects of not doing that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've written more about the explanation below. Actually, it's a good question whether there is reasoning behind updating lastPosition. Wouldn't be surprised, if it is just an artifact of some bug-fixing attempt.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll review this.
One of the challenges with the VirtualFlow class is that there are a number of parameters that contain some state, and the behavior depends very often on what parameters are modified in which method, and when (in which order).

@FlorianKirmaier
Copy link
Member Author

FlorianKirmaier commented Mar 7, 2023

Some explanation:

The layout method contains logic, to skip the layouting.

            if (width == lastWidth &&
                height == lastHeight &&
                cellCount == lastCellCount &&
                isVertical == lastVertical &&
                position == lastPosition &&
                ! cellSizeChanged)
            {
                // TODO this happens to work around the problem tested by
                // testCellLayout_LayoutWithoutChangingThingsUsesCellsInSameOrderAsBefore
                // but isn't a proper solution. Really what we need to do is, when
                // laying out cells, we need to make sure that if a cell is pressed
                // AND we are doing a full rebuild then we need to make sure we
                // use that cell in the same physical location as before so that
                // it gets the mouse release event.
                return;
            }

So, when the position is changed, then the content should be layout again.
But when we reset the oldPosition, to the current position, somewhere else in the code - then we interfere with this logic.
This has the effect, that the layout is skipped.
For that reason, it seems wrong to me, to change the "last-something" values outside of this method.

So I removed the resetting of the lastPosition in the scrollPixels method.
lastPosition = getPosition();
I also don't see a reason, why the lastPosition should be set anyways.

But I have to admit, that I don't understand the class well enough to ensure this is correct based on logic. This fixes the unit test and doesn't seem to break tests or something obvious in applications according to my tests.

@ebresie
Copy link

ebresie commented Mar 11, 2023

Some explanation:

The layout method contains logic, to skip the layouting.

So, when the position is changed, then the content should be layout again. But when we reset the oldPosition, to the current position, somewhere else in the code - then we interfere with this logic. This has the effect, that the layout is skipped. For that reason, it seems wrong to me, to change the "last-something" values outside of this method.

So I removed the resetting of the lastPosition in the scrollPixels method. lastPosition = getPosition(); I also don't see a reason, why the lastPosition should be set anyways.

But I have to admit, that I don't understand the class well enough to ensure this is correct based on logic. This fixes the unit test and doesn't seem to break tests or something obvious in applications according to my tests.

Just curious…based on the explanation above about change/not changes, does the call to getPosition help in the case state may (or may not) have changed to ensure there is no stale state at that time?

Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this fix with the MonkeyTester app on Macos Ventura 13.1
https://github.com/andy-goryachev-oracle/Test/blob/main/src/goryachev/monkey/MonkeyTesterApp.java

Could not see any ill effects - navigation works, selection works, variable height cells work.

@johanvos
Copy link
Collaborator

The patch looks ok, and the test fails before and passes after. No regression is observed. Also, the explanation about the changed position outside the layout process makes sense.
The only hesitation I still have is why the lastPosition = getPosition(); is there in the first place.
As I wrote before, there are many implicit rules in this class, e.g. only change layout-related properties inside the layout cycle ; but there are methods that are called from within the layoutChildren method as well as from methods that are triggered by different inputs.

I'm approving this, as the removal of this line is in line with the general approach here where we don't change the lastXXX properties outside the layout process -- as Florian mentioned as well.

@openjdk
Copy link

openjdk bot commented Mar 16, 2023

@FlorianKirmaier This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8303680: Virtual Flow freezes after calling scrollTo and scrollPixels in succession

Reviewed-by: angorya, jvos

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 7 new commits pushed to the master branch:

  • 935c7b7: 8301009: Update libxml2 to 2.10.3
  • 147d71f: 8178368: Right alignment of text fields and alignment of prompt text works incorrectly
  • 4051f16: 8299968: Second call to Stage.setScene() create sizing issue with uiScale > 1.0
  • df22c41: 8302355: Public API for Toolkit.canStartNestedEventLoop()
  • 8cda7bc: 8302797: ArrayIndexOutOfBoundsException in TextRun.getWrapIndex()
  • 4178ad7: 8090123: Items are no longer visible when collection is changed
  • bbdc599: 8303217: Webview loaded webpage is not showing play, volume related buttons for embeded Audio/Video elements

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@kevinrushforth, @andy-goryachev-oracle, @johanvos) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Ready to be integrated label Mar 16, 2023
@FlorianKirmaier
Copy link
Member Author

/integrate
Thank you for the quick review!

@FlorianKirmaier
Copy link
Member Author

/integrate

@openjdk openjdk bot added the sponsor Ready to sponsor label Mar 16, 2023
@openjdk
Copy link

openjdk bot commented Mar 16, 2023

@FlorianKirmaier
Your change (at version 28bdb0b) is now ready to be sponsored by a Committer.

@andy-goryachev-oracle
Copy link
Contributor

/sponsor

@openjdk
Copy link

openjdk bot commented Mar 16, 2023

@FlorianKirmaier
Your change (at version 28bdb0b) is now ready to be sponsored by a Committer.

@openjdk
Copy link

openjdk bot commented Mar 16, 2023

Going to push as commit 6be8703.
Since your change was applied there have been 7 commits pushed to the master branch:

  • 935c7b7: 8301009: Update libxml2 to 2.10.3
  • 147d71f: 8178368: Right alignment of text fields and alignment of prompt text works incorrectly
  • 4051f16: 8299968: Second call to Stage.setScene() create sizing issue with uiScale > 1.0
  • df22c41: 8302355: Public API for Toolkit.canStartNestedEventLoop()
  • 8cda7bc: 8302797: ArrayIndexOutOfBoundsException in TextRun.getWrapIndex()
  • 4178ad7: 8090123: Items are no longer visible when collection is changed
  • bbdc599: 8303217: Webview loaded webpage is not showing play, volume related buttons for embeded Audio/Video elements

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Mar 16, 2023
@openjdk openjdk bot closed this Mar 16, 2023
@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review labels Mar 16, 2023
@openjdk openjdk bot removed the sponsor Ready to sponsor label Mar 16, 2023
@openjdk
Copy link

openjdk bot commented Mar 16, 2023

@andy-goryachev-oracle @FlorianKirmaier Pushed as commit 6be8703.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
5 participants