This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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.
Fix ImageReader may leak images when onDraw() not called #24272
Fix ImageReader may leak images when onDraw() not called #24272
Changes from all commits
1b8fda8
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like there is some misunderstanding from my side. The error message " Unable to acquire a buffer item, very likely client tried to acquire more than maxImages buffers" suggests that
imageReader.acquireLatestImage()
was called even thoughimageOpenedCount
is less thanimageReader.getMaxImages()
. Unless there's a bug in this logic, shouldn't it be preventing theacquireLatestImage()
call?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blasten I guess maybe the newest available image will be also counted by the code in ImageReader.cpp.
Let me have a deeper view in ImageReader.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blasten I read the code and document of
acquireLatestImage()
in ImageReader.java carefully and I finally know why the error message comes even though the openedCount is less than maxImages.The code:
https://cs.android.com/android/platform/superproject/+/master:frameworks/base/media/java/android/media/ImageReader.java;drc=master;l=410?q=two
The doc of
acquireLatestImage()
says:So it needs at least two reserved slots in buffer before one calling of
acquireLatestImage()
. And the implementation code is as same as it described:Every
nativeImageSetup()
will need a new BufferItem in cpp,acquireNextSurfaceImage()
callsnativeImageSetup()
. then looking at theacquireLatestImage()
logic, it callsacquireNextImage()
and callsacquireNextImageNoThrowISE
in the for-loop and close the last image unless the next is null. So It can really need two slots.The code of this pull request fixs onDraw() may be lesser then invalidate(), and try to make the code logic neat and easy to maintain by closing the previous image if exists after
reader.acquireLatestImages()
and removing the queue and the counter.