RFR: 8297923: java.awt.ScrollPane broken after multiple scroll up/down

Alexey Ivanov aivanov at openjdk.org
Tue Sep 5 12:57:52 UTC 2023


On Tue, 6 Jun 2023 16:07:53 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

> **Problem description**
> 
> If you grab the thumb of the scroll bar of `ScrollPane` and drag it slowly and continuously up and down, you'll notice the UI stops rendering correctly: the child component of the scroll pane will render on the left of the frame itself, the inside of the scroll pane will be filled with the background color of its child component.
> 
> **Root cause**
> 
> AWT calls the [`::SetScrollInfo`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setscrollinfo) function on EDT when AWT processes scroll bar tracking events. This Windows API is not thread-safe, calling this function on an incorrect thread leads to leaking GDI objects.
> 
> When the process reaches the limit on the number of GDI objects, it cannot create new GDI objects, which results in rendering issues.
> 
> **Fix**
> 
> To resolve the problem, I modified the code so that `::SetScrollInfo` and [`::GetScrollInfo`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getscrollinfo) are always called on the toolkit thread, all AWT components are created on the toolkit thread.
> 
> An automatic test is provided. The test scrolls the vertical scroll bar up and down. Then the test takes a screenshot. When the bug is reproduced, the robot cannot create new GDI objects to capture the screenshot and it throws `OutOfMemoryError`.

I have submitted the follow-up bugs.

> Probably we should update the Java_sun_awt_windows_WScrollbarPeer_setValues as well? it calls the SetScrollInfo. [⇑](https://github.com/openjdk/jdk/pull/14338#issuecomment-1579851933)

[JDK-8315690](https://bugs.openjdk.org/browse/JDK-8315690): Call ::SetScrollInfo on toolkit thread in awt.ScrollBar

> In addition to that, `WScrollPanePeer.getScrollOffset` is unused, so it's never called. [⇑](https://github.com/openjdk/jdk/pull/14338#discussion_r1220111236)

[JDK-8315691](https://bugs.openjdk.org/browse/JDK-8315691): Remove unused WScrollPanePeer.getScrollOffset method

> There's also a specific `WM_AWT_SET_SCROLL_INFO` message to call `::SetScrollInfo`. This message is never used, it can also be removed. [⇑](https://github.com/openjdk/jdk/pull/14338#discussion_r1221395024)

[JDK-8315693](https://bugs.openjdk.org/browse/JDK-8315693): Remove WM_AWT_SET_SCROLL_INFO message

-------------

PR Comment: https://git.openjdk.org/jdk/pull/14338#issuecomment-1706567768


More information about the client-libs-dev mailing list