Skip to content

Commit d303dd3

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Prevent NPE in TextureView.getBitmap()" into jb-dev
2 parents 9ac3204 + 78245f7 commit d303dd3

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)