Skip to content

Commit 78245f7

Browse files
author
Romain Guy
committed
Prevent NPE in TextureView.getBitmap()
This crash could occur when invoking setSurfaceTexture() then getBitmap() before the View has a chance to be drawn. Change-Id: I25c55df15750e59b9c916e8f750de2c89718d39e
1 parent c9c275f commit 78245f7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

core/java/android/view/TextureView.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,17 @@ public Bitmap getBitmap(Bitmap bitmap) {
561561
applyUpdate();
562562
applyTransformMatrix();
563563

564-
mLayer.copyInto(bitmap);
564+
// This case can happen if the app invokes setSurfaceTexture() before
565+
// we are able to create the hardware layer. We can safely initialize
566+
// the layer here thanks to the validate() call at the beginning of
567+
// this method
568+
if (mLayer == null && mUpdateSurface) {
569+
getHardwareLayer();
570+
}
571+
572+
if (mLayer != null) {
573+
mLayer.copyInto(bitmap);
574+
}
565575
}
566576
return bitmap;
567577
}

0 commit comments

Comments
 (0)