Bug 1358885 - Check VRManagerChild is created in GampadManager for avoiding crash on Android. r=kip, a=gchang
authorDaosheng Mu <daoshengmu@gmail.com>
Wed, 10 May 2017 20:30:00 -0400
changeset 396235 c4be8f11de51bf72b3f5865f6942553ba0a8e273
parent 396234 4217bd24eb34e1016c8247a9678ce5826372bd20
child 396236 ea3a47d36b6aa3ac2c2ea55e059c7c9eefe664f8
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskip, gchang
bugs1358885
milestone54.0
Bug 1358885 - Check VRManagerChild is created in GampadManager for avoiding crash on Android. r=kip, a=gchang MozReview-Commit-ID: I0fimVQKAHy
dom/gamepad/GamepadManager.cpp
dom/gamepad/GamepadManager.h
--- a/dom/gamepad/GamepadManager.cpp
+++ b/dom/gamepad/GamepadManager.cpp
@@ -106,20 +106,20 @@ void
 GamepadManager::StopMonitoring()
 {
   for (uint32_t i = 0; i < mChannelChildren.Length(); ++i) {
     mChannelChildren[i]->SendGamepadListenerRemoved();
   }
   mChannelChildren.Clear();
   mGamepads.Clear();
 
-#if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_LINUX)
-  mVRChannelChild = gfx::VRManagerChild::Get();
-  mVRChannelChild->SendControllerListenerRemoved();
-#endif
+  if (gfx::VRManagerChild::IsCreated()) {
+    gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
+    vm->SendControllerListenerRemoved();
+  }
 }
 
 void
 GamepadManager::BeginShutdown()
 {
   mShuttingDown = true;
   StopMonitoring();
   // Don't let windows call back to unregister during shutdown
@@ -678,22 +678,22 @@ GamepadManager::ActorCreated(PBackground
   if (NS_WARN_IF(!initedChild)) {
     ActorFailed();
     return;
   }
   MOZ_ASSERT(initedChild == child);
   child->SendGamepadListenerAdded();
   mChannelChildren.AppendElement(child);
 
-#if defined(XP_WIN) || defined(XP_MACOSX) || defined(XP_LINUX)
-  // Construct VRManagerChannel and ask adding the connected
-  // VR controllers to GamepadManager
-  mVRChannelChild = gfx::VRManagerChild::Get();
-  mVRChannelChild->SendControllerListenerAdded();
-#endif
+  if (gfx::VRManagerChild::IsCreated()) {
+    // Construct VRManagerChannel and ask adding the connected
+    // VR controllers to GamepadManager
+    gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
+    vm->SendControllerListenerAdded();
+  }
 }
 
 //Override nsIIPCBackgroundChildCreateCallback
 void
 GamepadManager::ActorFailed()
 {
   MOZ_CRASH("Gamepad IPC actor create failed!");
 }
--- a/dom/gamepad/GamepadManager.h
+++ b/dom/gamepad/GamepadManager.h
@@ -119,17 +119,16 @@ class GamepadManager final : public nsIO
   // true when shutdown has begun
   bool mShuttingDown;
 
   // Gamepad IPDL child
   // This pointer is only used by this singleton instance and
   // will be destroyed during the IPDL shutdown chain, so we
   // don't need to refcount it here.
   nsTArray<GamepadEventChannelChild *> mChannelChildren;
-  gfx::VRManagerChild* mVRChannelChild;
 
  private:
 
   nsresult Init();
 
   bool MaybeWindowHasSeenGamepad(nsGlobalWindow* aWindow, uint32_t aIndex);
   // Returns true if we have already sent data from this gamepad
   // to this window. This should only return true if the user