On Wed, 8 Oct 2025 04:47:10 GMT, Ambarish Rapte <[email protected]> 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.

Marked as reviewed by jdv (Committer).

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

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

Reply via email to