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

JDK-8283401: ArrayIndexOutOfBoundsException when disconnecting screen(s) #1200

Conversation

Maran23
Copy link
Member

@Maran23 Maran23 commented Aug 5, 2023

When the D3DPipeline is reinitialized, the adapter ordinal of all the Screens are outdated.
As a consequence, when a D3DResourceFactory is created for a Screen (adapter ordinal), the code may fail with an ArrayIndexOutOfBoundsException as the ordinal is higher than what we would expect it to be.

Example:
We have 3 screens. Adapter ordinal 0, 1, 2.
If we now disconnect 2 screens, we only have one screen left.
The D3DPipeline is reinitialized as a D3DERR_DEVICEREMOVED is reported from Direct3d9.
Now the remaining screen may have the adapter ordinal 1 (from before). But since we only have 1 screen left, it should have the adapter ordinal 0.

Direct3d9 will also return 0 as adapter ordinal if you call it. And that is what we do to update the Screen and fix this problem.

See also the ticket for information how to reproduce this problem (Windows only).


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-8283401: ArrayIndexOutOfBoundsException when disconnecting screen(s) (Bug - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1200

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 5, 2023

👋 Welcome back mhanl! 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 Aug 5, 2023
@mlbridge
Copy link

mlbridge bot commented Aug 5, 2023

Webrevs

@kevinrushforth
Copy link
Member

Thanks for tracking this down. I'll review and do some testing of this next week.

Reviewers: @kevinrushforth @arapte

/reviewers 2

@openjdk
Copy link

openjdk bot commented Aug 5, 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).

@mstr2
Copy link
Collaborator

mstr2 commented Aug 9, 2023

I tested the patch with a docking station and two external displays like this:

  1. Put Windows into sleep mode
  2. Disconnect the docking station / external monitor
  3. Resume Windows

Without the patch, the exception occurs. With the patch applied, everything works as expected.

I notice that the logic to assign adapter ordinals is now duplicated in two places in the codebase. Have you thought about moving the implementation into the Screen class? Here's how that could work:

Remove Screen.setAdapterOrdinal(int) and add the following method to the Screen class:

    public static void updateAdapterOrdinals() {
        for (Screen screen : getScreens()) {
            screen.adapter = GraphicsPipeline.getPipeline().getAdapterOrdinal(screen);
        }
    }

Remove QuantumToolkit.assignScreenAdapters() and call Screen.updateAdapterOrdinals() from the two call sites instead. You can then just call Screen.updateAdapterOrdinals() from D3DPipeline as well.

For good measure, you could initialize Screen.adapter to -1 and change Screen.getAdapterOrdinal() as follows:

    public int getAdapterOrdinal() {
+       if (adapter < 0) {
+           throw new IllegalStateException("Adapter ordinal is not initialized.");
+       }
+
        return adapter;
    }

@Maran23
Copy link
Member Author

Maran23 commented Aug 9, 2023

I notice that the logic to assign adapter ordinals is now duplicated in two places in the codebase. Have you thought about moving the implementation into the Screen class?

I actually considered this but I really want to keep the diff in this PR as small as possible, as this is a very sensitive area. If something is broken here, it will affect a lot of Windows users.
IMO this is a good idea for a follow up PR, as soon as this one is merged.

@mstr2
Copy link
Collaborator

mstr2 commented Aug 9, 2023

I actually considered this but I really want to keep the diff in this PR as small as possible, as this is a very sensitive area. If something is broken here, it will affect a lot of Windows users. IMO this is a good idea for a follow up PR, as soon as this one is merged.

Wouldn't this just impose the compatibility risk again onto the next PR? The diff is very small in both cases.

@kevinrushforth
Copy link
Member

I actually considered this but I really want to keep the diff in this PR as small as possible, as this is a very sensitive area. If something is broken here, it will affect a lot of Windows users. IMO this is a good idea for a follow up PR, as soon as this one is merged.

Wouldn't this just impose the compatibility risk again onto the next PR? The diff is very small in both cases.

I prefer the approach taken in this PR to minimize the diffs. One benefit is that I could imagine, for example, wanting to backport this small fix once it is integrated and has baked for a while. I would have no desire to backport what is otherwise just a refactoring to eliminate duplicate code.

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.

The code change looks good.

I am not able to provoke the bug, but I did test it enough to validate the logic, by simulating device lost and verifying that the adapter ordinals are all reinitialized correctly.

@openjdk
Copy link

openjdk bot commented Aug 11, 2023

@Maran23 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:

8283401: ArrayIndexOutOfBoundsException when disconnecting screen(s)

Reviewed-by: kcr, mstrauss

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 6 new commits pushed to the master branch:

  • 8998b2d: 8314141: Missing default for switch in CreateBitmap
  • 5d74176: 8313181: Enabling modern media controls on webkit 616.1 does not load button images on HTML5 video Element
  • 9f180e2: 8313900: Possible NULL pointer access in NativeAudioSpectrum and NativeVideoBuffer
  • 771273f: 8313799: Remove lockItemOnEdit flag from (Tree)TableCell
  • 1752b62: 8313856: Replace VLA with malloc in pango
  • af8950e: 8313711: Cherry-pick WebKit 616.1 stabilization fixes

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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Ready to be integrated label Aug 11, 2023
@Maran23
Copy link
Member Author

Maran23 commented Aug 11, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Aug 11, 2023

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

  • bedb964: 8307316: Let JavaFX be built on unknown architectures
  • 8998b2d: 8314141: Missing default for switch in CreateBitmap
  • 5d74176: 8313181: Enabling modern media controls on webkit 616.1 does not load button images on HTML5 video Element
  • 9f180e2: 8313900: Possible NULL pointer access in NativeAudioSpectrum and NativeVideoBuffer
  • 771273f: 8313799: Remove lockItemOnEdit flag from (Tree)TableCell
  • 1752b62: 8313856: Replace VLA with malloc in pango
  • af8950e: 8313711: Cherry-pick WebKit 616.1 stabilization fixes

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Aug 11, 2023

@Maran23 Pushed as commit a5183e5.

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

@Maran23
Copy link
Member Author

Maran23 commented Aug 11, 2023

Thanks for the reviews!
@mstr2 I will file a follow-up in the next days to avoid the code duplications.

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
3 participants