Skip to content
This repository was archived by the owner on Jun 16, 2023. It is now read-only.

Commit 9c0b87e

Browse files
cristianoccazinspcristianocca
andauthoredSep 21, 2021
fix: Remove the mCamera.setPreviewDisplay call on surface destroy as it may cause ANRs or slow down the UI when unmounting. The side effect of this is a nasty warning BufferQueue has been abandoned that can be ignored. (#3331)
Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
1 parent 0defb57 commit 9c0b87e

File tree

1 file changed

+11
-6
lines changed
  • android/src/main/java/com/google/android/cameraview

1 file changed

+11
-6
lines changed
 

Diff for: ‎android/src/main/java/com/google/android/cameraview/Camera1.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,17 @@ public void onSurfaceDestroyed() {
177177
// it may have been destroyed already.
178178
// Do not lock as it would freeze the UI if the camera is being released
179179
if (mCamera != null) {
180-
try {
181-
// mCamera.setPreviewCallback(null); // Not needed as stop() already clears it
182-
mCamera.setPreviewDisplay(null); // needed to prevent buffer abandoned logs
183-
} catch (Exception e) {
184-
Log.e("CAMERA_1::", "onSurfaceDestroyed preview cleanup failed", e);
185-
}
180+
// After a lot of testing, setPreviewDisplay may cause ANRs if called on the UI
181+
// thread. The buffer abandoned warning ended up being harmess, so we can comment this
182+
// out for now until the surface change events are dispatched in a non-UI thread.
183+
// Therefore, the below lines are no longer needed and will prevent the app from
184+
// hanging in some situations, or even make the app more responsive when unmounting.
185+
// try {
186+
// // mCamera.setPreviewCallback(null); // Not needed as stop() already clears it
187+
// mCamera.setPreviewDisplay(null); // needed to prevent buffer abandoned logs
188+
// } catch (Exception e) {
189+
// Log.e("CAMERA_1::", "onSurfaceDestroyed preview cleanup failed", e);
190+
// }
186191
mBgHandler.post(new Runnable() {
187192
@Override
188193
public void run() {

0 commit comments

Comments
 (0)