@@ -431,6 +431,12 @@ WindowsGamepadService::ScanForXInputDevices()
431431 MOZ_ASSERT (mXInput , " XInput should be present!" );
432432
433433 bool found = false ;
434+ RefPtr<GamepadPlatformService> service =
435+ GamepadPlatformService::GetParentService ();
436+ if (!service) {
437+ return found;
438+ }
439+
434440 for (int i = 0 ; i < XUSER_MAX_COUNT; i++) {
435441 XINPUT_STATE state = {};
436442 if (mXInput .mXInputGetState (i, &state) != ERROR_SUCCESS) {
@@ -443,9 +449,6 @@ WindowsGamepadService::ScanForXInputDevices()
443449 }
444450
445451 // Not already present, add it.
446- GamepadPlatformService* service =
447- GamepadPlatformService::GetParentService ();
448- MOZ_ASSERT (service);
449452 Gamepad gamepad = {};
450453 gamepad.type = kXInputGamepad ;
451454 gamepad.present = true ;
@@ -466,6 +469,12 @@ WindowsGamepadService::ScanForXInputDevices()
466469void
467470WindowsGamepadService::ScanForDevices ()
468471{
472+ RefPtr<GamepadPlatformService> service =
473+ GamepadPlatformService::GetParentService ();
474+ if (!service) {
475+ return ;
476+ }
477+
469478 for (int i = mGamepads .Length () - 1 ; i >= 0 ; i--) {
470479 mGamepads [i].present = false ;
471480 }
@@ -486,9 +495,6 @@ WindowsGamepadService::ScanForDevices()
486495 }
487496
488497 // Look for devices that are no longer present and remove them.
489- GamepadPlatformService* service =
490- GamepadPlatformService::GetParentService ();
491- MOZ_ASSERT (service);
492498 for (int i = mGamepads .Length () - 1 ; i >= 0 ; i--) {
493499 if (!mGamepads [i].present ) {
494500 service->RemoveGamepad (mGamepads [i].id );
@@ -516,9 +522,11 @@ WindowsGamepadService::PollXInput()
516522
517523void WindowsGamepadService::CheckXInputChanges (Gamepad& gamepad,
518524 XINPUT_STATE& state) {
519- GamepadPlatformService* service =
525+ RefPtr< GamepadPlatformService> service =
520526 GamepadPlatformService::GetParentService ();
521- MOZ_ASSERT (service);
527+ if (!service) {
528+ return ;
529+ }
522530 // Handle digital buttons first
523531 for (size_t b = 0 ; b < kNumMappings ; b++) {
524532 if (state.Gamepad .wButtons & kXIButtonMap [b].button &&
@@ -586,6 +594,12 @@ class HidValueComparator {
586594bool
587595WindowsGamepadService::GetRawGamepad (HANDLE handle)
588596{
597+ RefPtr<GamepadPlatformService> service =
598+ GamepadPlatformService::GetParentService ();
599+ if (!service) {
600+ return true ;
601+ }
602+
589603 if (!mHID ) {
590604 return false ;
591605 }
@@ -722,10 +736,6 @@ WindowsGamepadService::GetRawGamepad(HANDLE handle)
722736 gamepad.type = kRawInputGamepad ;
723737 gamepad.handle = handle;
724738 gamepad.present = true ;
725-
726- GamepadPlatformService* service =
727- GamepadPlatformService::GetParentService ();
728- MOZ_ASSERT (service);
729739 gamepad.id = service->AddGamepad (gamepad_id,
730740 GamepadMappingType::_empty,
731741 gamepad.numButtons ,
@@ -741,6 +751,12 @@ WindowsGamepadService::HandleRawInput(HRAWINPUT handle)
741751 return false ;
742752 }
743753
754+ RefPtr<GamepadPlatformService> service =
755+ GamepadPlatformService::GetParentService ();
756+ if (service) {
757+ return true ;
758+ }
759+
744760 // First, get data from the handle
745761 UINT size;
746762 GetRawInputData (handle, RID_INPUT, nullptr , &size, sizeof (RAWINPUTHEADER));
@@ -773,9 +789,6 @@ WindowsGamepadService::HandleRawInput(HRAWINPUT handle)
773789 reinterpret_cast <PHIDP_PREPARSED_DATA>(parsedbytes.Elements ());
774790
775791 // Get all the pressed buttons.
776- GamepadPlatformService* service =
777- GamepadPlatformService::GetParentService ();
778- MOZ_ASSERT (service);
779792 nsTArray<USAGE> usages (gamepad->numButtons );
780793 usages.SetLength (gamepad->numButtons );
781794 ULONG usageLength = gamepad->numButtons ;
0 commit comments