fix: defensively release virtualDisplay before creation#78
Merged
SamuelBrucksch merged 2 commits intoMay 18, 2026
Conversation
In pathological cases, `onSurfaceDestroyed` is never called and the cleanup in `onSurfaceDestroyed` (`virtualDisplay?.release()`) never runs. Each call to `onSurfaceAvailable` orphans the previous `VirtualDisplay` that remains alive consuming framebuffers, but with no reference to release it.
Contributor
|
No significant issues found. |
Contributor
|
Thanks for checking and opening this PR. We will have a look. |
Contributor
|
This seems to be a fun quirk of an Automotive OEM adjustment. It properly calls the onSurfaceDestroyed on Android Auto and the AVD. Thanks for checking. We will release a new version soon, so it can be used in ABRP too. |
SamuelBrucksch
approved these changes
May 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In pathological cases,
onSurfaceDestroyedis never called and the cleanup inonSurfaceDestroyed(virtualDisplay?.release()) never runs. Each call toonSurfaceAvailableorphans the previousVirtualDisplaythat remains alive consuming framebuffers, but with no reference to release it.This is likely a bug higher up in the stack (CarAppActivity), but good to protect against it.
I encountered this issue when running ABRP on Android Automotive, repeated
onSurfaceAvailablecallbacks without correspondingonSurfaceDestroyedcallbacks causeVirtualDisplayinstances to leak inVirtualRenderer.kt. Each leaked virtual display exhausts GPU resources andsurfaceflingereventually crashes when it tries to create a texture with:Reproduced with something like:
and monitored increasing virtual displays with