From 189a2dcac031eec76abe2d2f1a30140274b01199 Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Wed, 4 Sep 2019 16:27:18 +0200 Subject: [PATCH] Fix crash when the app is closed while playing 360 videos --- .../shared/org/mozilla/vrbrowser/VRBrowserActivity.java | 6 +++--- .../shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java | 5 +---- .../shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java | 6 ++++++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java index 6f36e8c02..1162c131e 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java @@ -395,8 +395,6 @@ protected void onDestroy() { } // Remove all widget listeners - mTray.removeListeners(mWindows); - mTray.onDestroy(); mWindows.onDestroy(); SessionStore.get().onDestroy(); @@ -1207,7 +1205,9 @@ public void popWorldBrightness(Object aKey) { @Override public void setTrayVisible(boolean visible) { - mTray.setTrayVisible(visible); + if (mTray != null && !mTray.isReleased()) { + mTray.setTrayVisible(visible); + } } @Override diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java index 4e0a55885..6dce9b306 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/TrayWidget.java @@ -218,10 +218,6 @@ public void removeListeners(TrayListener... listeners) { mTrayListeners.removeAll(Arrays.asList(listeners)); } - public void onDestroy() { - mTrayListeners.clear(); - } - private void notifyBookmarksClicked() { mTrayListeners.forEach(TrayListener::onBookmarksClicked); } @@ -266,6 +262,7 @@ public void releaseWidget() { } mWidgetManager.removeUpdateListener(this); + mTrayListeners.clear(); super.releaseWidget(); } diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java index f0df2feeb..26cd15126 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/UIWidget.java @@ -49,6 +49,7 @@ public interface Delegate { protected int mBorderWidth; private Runnable mFirstDrawCallback; protected boolean mResizing = false; + protected boolean mReleased = false; public UIWidget(Context aContext) { super(aContext); @@ -203,6 +204,11 @@ private void releaseRenderer() { public void releaseWidget() { releaseRenderer(); mWidgetManager = null; + mReleased = true; + } + + public boolean isReleased() { + return mReleased; } @Override