RFR: 8368879: Intermittent crash on exit when disposing MTLRTTextureData

Kevin Rushforth kcr at openjdk.org
Wed Oct 8 15:27:30 UTC 2025


On Wed, 8 Oct 2025 04:47:10 GMT, Ambarish Rapte <arapte at openjdk.org> wrote:

> **Issue**:
> Intermittent crash on exit in `MTLRTTextureData::dispose()` during toolkit shutdown
> The crash is very rare and difficult to reproduce.
> 
> **Cause**:
> While exiting an app, in `MTLContext.dispose()`, a Texture is released **after** the native peer MetalConext is disposed.
> - MTLContext.dispose() method:
> 
>     @Override
>     public void dispose() {
>         nRelease(pContext);
>         state = null;
>         super.dispose();
>     }
> 
> 
> 1. The `MTLContext.dispose()` method releases the native peer (`nRelease(pContext)`) before calling `super.dispose()` (i.e., `BaseShaderContext.dispose()`).
> 2. `BaseShaderContext.dispose()` calls `disposeLCDBuffer()` to dispose the LCD texture, which in turn invokes `MTLRTTextureData::dispose()`
> => As native MetalContext is already disposed, it causes a crash.
> 
> **Fix**:
> Call `disposeLCDBuffer()` before `nRelease(pContext)`. so that the Texture is released **before** disposing the native peer MetalContext.
> The scenario is very rare to reproduce, so no test is added.

LGTM

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

Marked as reviewed by kcr (Lead).

PR Review: https://git.openjdk.org/jfx/pull/1931#pullrequestreview-3315397389


More information about the openjfx-dev mailing list