RFR: 8352209: NPE com.sun.prism.d3d.D3DTextureData.getContext [v3]
Kevin Rushforth
kcr at openjdk.org
Thu Oct 30 16:50:54 UTC 2025
On Thu, 30 Oct 2025 14:08:38 GMT, Lukasz Kostyra <lkostyra at openjdk.org> wrote:
>> This PR fixes NPE thrown when trying to update D3D texture in some rare scenarios.
>>
>> On more stressful cases (like the one using Canvas attached to this issue) it is possible that a D3DTexture.update() call will go through after the Resource Pool already pruned the underlying Texture's resource. This in turn caused an NPE, which propagated to higher levels and disrupted the rendering loop, causing the Canvas to not be drawn anymore. The update() call seems not to be called more than once on an already freed resource, suggesting this is some sort of rare race between the pool and the drawing code.
>>
>> This change prevents the NPE from being thrown. I noticed no visual problems with the test even when the update() call is rejected by the newly added check. Best way to verify it is to add a log call inside added `if (!resource.isValid())` blocks when running the test, it will occasionally get printed but the test itself won't change its behavior like it does without this change.
>
> Lukasz Kostyra has updated the pull request incrementally with one additional commit since the last revision:
>
> BaseContext: Add maskTex checks to flushMask()
Since this has expanded beyond D3D we will need to test it on all platforms. Also, it may be that you have found the root cause of [JDK-8368629](https://bugs.openjdk.org/browse/JDK-8368629), which @arapte filed to track the root cause of a similar bug (his was a crash rather than an NPE), [JDK-8368631](https://bugs.openjdk.org/browse/JDK-8368631), that caused him to add the check for valid texture resource in `MTLTexture`.
If you can verify that this does indeed fix [JDK-8368629](https://bugs.openjdk.org/browse/JDK-8368629), then it might be better to close [JDK-8352209](https://bugs.openjdk.org/browse/JDK-8352209) as a duplicate and change the title of this PR to point to use [JDK-8368629](https://bugs.openjdk.org/browse/JDK-8368629). If not, it still seems worth changing the title of this PR (and JBS issue) to something more generic.
Also, what do you think about adding the null assignment to the ES2 pipeline?
modules/javafx.graphics/src/main/java/com/sun/prism/impl/BaseContext.java line 111:
> 109:
> 110: protected final void flushMask() {
> 111: if (maskTex != null && maskTex.isSurfaceLost()) return;
if maskText is null the subsequent calls could throw NPE, so maybe this should be:
if (maskTex == null || maskTex.isSurfaceLost()) return;
-------------
PR Review: https://git.openjdk.org/jfx/pull/1951#pullrequestreview-3400224223
PR Review Comment: https://git.openjdk.org/jfx/pull/1951#discussion_r2478535551
More information about the openjfx-dev
mailing list