From 8bc511e4eb2f306350a6710dea5e5ec250fe696c Mon Sep 17 00:00:00 2001 From: John Reck Date: Mon, 18 May 2015 15:11:52 -0700 Subject: [PATCH] Fix NPE in setSurfaceTexure Bug: 20088412 Change-Id: I9b78636a7d89438c8924bb1bf2adba00e74366eb --- core/java/android/view/TextureView.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java index d70712ac327b8..ad7d04e1fe1da 100644 --- a/core/java/android/view/TextureView.java +++ b/core/java/android/view/TextureView.java @@ -730,9 +730,13 @@ public class TextureView extends View { } mSurface = surfaceTexture; - // If the view is visible, update the listener in the new surface to use - // the existing listener in the view. - if (((mViewFlags & VISIBILITY_MASK) == VISIBLE)) { + /* + * If the view is visible and we already made a layer, update the + * listener in the new surface to use the existing listener in the view. + * Otherwise this will be called when the view becomes visible or the + * layer is created + */ + if (((mViewFlags & VISIBILITY_MASK) == VISIBLE) && mLayer != null) { mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler); } mUpdateSurface = true;