RFR: 8368629: Texture.update sometimes invoked for a disposed Texture [v5]
John Hendrikx
jhendrikx at openjdk.org
Fri Nov 7 09:14:23 UTC 2025
On Tue, 4 Nov 2025 14:49:56 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:
>
> Review comments - MTLTexture: add isValid() check to update(MediaFrame)
I also made this hack (using internals) to display some vram usage information (in a title bar for example). This helps me at least to see how "bad" the situation is currently:
import com.sun.glass.ui.Screen;
import com.sun.prism.GraphicsPipeline;
import com.sun.prism.ResourceFactory;
import com.sun.prism.impl.TextureResourcePool;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class VramStats {
public static String getVramStats() {
GraphicsPipeline pipeline = GraphicsPipeline.getPipeline();
if(pipeline == null) {
return "Unavailable";
}
List<Screen> screens = Screen.getScreens();
Set<TextureResourcePool<?>> uniquePools = new HashSet<>();
for(Screen screen : screens) {
ResourceFactory resourceFactory = pipeline.getResourceFactory(screen);
uniquePools.add(resourceFactory.getTextureResourcePool());
}
long totalUsed = 0;
for(TextureResourcePool<?> pool : uniquePools) {
totalUsed += pool.used();
}
return "VRAM: " + (totalUsed / 1024 / 1024) + " MB";
}
}
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1951#issuecomment-3501416090
More information about the openjfx-dev
mailing list