You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 91d9b9c
Browse filesBrowse the repository at this point in the historyBrowse files
[Android] Fix use-after-free of SurfaceControl.Transaction in HCPP (flutter#192969)
Fixes a native `SIGABRT` in `SurfaceComposerClient::Transaction` that we
were seeing with HCPP under heavy platform view churn.
`createTransaction()` was adding the transaction to
`pendingRasterTransactions` before handing it back to native, but
`AHBSwapchainImplVK::Present()` keeps writing into it after that
(`setBuffer`, `setOnComplete`). So the platform thread could merge or
close it mid-write. Separately, nothing was holding a reference to the
Java object (`ASurfaceTransaction_fromJava` doesn't take one), so it
could also just get GC'd out from under us.
This splits creation from publication. Native now gets an unpublished
transaction, holds a global ref to it while writing, and calls
`publishTransaction` from `SurfaceTransaction::Apply()` after its last
write. If publishing fails for whatever reason (`FlutterJNI` is gone,
Java throws), we apply the transaction natively instead of dropping it,
so the completion callback still fires and we don't leak the buffer. I
don't think those paths are reachable today, but they're easy to just
handle.
On a stress test that cycles ~2,900 `SurfaceView`s per run on a low-core
emulator, this went from 24 aborts in 100 runs to 0 in 75.
It's a little awkward that the NDK only goes one direction here: there's
`ASurfaceTransaction_fromJava`, but no `toJava`. If we could create the
transaction natively and hand it to Java at the end, most of this
wouldn't be needed, might be feedback that is worth filing.
---------
Co-authored-by: Gray Mackall <[email protected]>
0 commit comments