From 137698f0fa191621bac65220a303b6c98d087edd Mon Sep 17 00:00:00 2001 From: VoidAwake Date: Wed, 5 Oct 2022 20:39:25 +1100 Subject: [PATCH 1/3] FIX: Add test for players joining after deleting an auto switched player --- .../InputSystem/Plugins/PlayerInputTests.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Assets/Tests/InputSystem/Plugins/PlayerInputTests.cs b/Assets/Tests/InputSystem/Plugins/PlayerInputTests.cs index 2686399225..f25095fefa 100644 --- a/Assets/Tests/InputSystem/Plugins/PlayerInputTests.cs +++ b/Assets/Tests/InputSystem/Plugins/PlayerInputTests.cs @@ -2242,6 +2242,37 @@ public void PlayerInput_WhenOverridingDeviceLayout_LostDeviceShouldBeResolvedAnd Assert.That(playerInput.devices[0], !Is.SameAs(gamepad)); // expected replacement (by design, not a requirement) Assert.That(playerInput.devices[0].name, Is.EqualTo(gamepad.name)); } + + [Test] + [Category("PlayerInput")] + public void PlayerInput_CanJoinPlayersThroughButtonPress_AfterAutoSwitchedPlayerDeleted() + { + var keyboard = InputSystem.AddDevice(); + + var prefab = new GameObject(); + prefab.SetActive(false); + + var prefabPlayerInput = prefab.AddComponent(); + prefabPlayerInput.actions = InputActionAsset.FromJson(kActions); + prefabPlayerInput.neverAutoSwitchControlSchemes = false; + + var player = PlayerInput.Instantiate(prefab); + + var gamepad = InputSystem.AddDevice(); + + Press(gamepad.buttonSouth); + + Object.DestroyImmediate(player); + + var manager = new GameObject(); + manager.SetActive(false); // Delay OnEnable() until we have all components. + + var managerComponent = manager.AddComponent(); + + manager.SetActive(true); + + Press(gamepad.buttonSouth); + } // An action is either // (a) button-like, or From adf7a8c76896a042eb3d83071387a2993bbf0e7b Mon Sep 17 00:00:00 2001 From: VoidAwake Date: Wed, 5 Oct 2022 20:41:28 +1100 Subject: [PATCH 2/3] FIX: Ensure callback arrays are unlocked when invoked and returning true --- .../InputSystem/Utilities/DelegateHelpers.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Packages/com.unity.inputsystem/InputSystem/Utilities/DelegateHelpers.cs b/Packages/com.unity.inputsystem/InputSystem/Utilities/DelegateHelpers.cs index b0c57d1282..ef4d443360 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Utilities/DelegateHelpers.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Utilities/DelegateHelpers.cs @@ -95,7 +95,11 @@ public static bool InvokeCallbacksSafe_AnyCallbackReturnsTrue( try { if (callbacks[i](argument1, argument2)) + { + callbacks.UnlockForChanges(); + Profiler.EndSample(); return true; + } } catch (Exception exception) { From 0dadb4bb3a25d0b704f49b18ebb6255a328f3628 Mon Sep 17 00:00:00 2001 From: VoidAwake Date: Wed, 5 Oct 2022 21:04:44 +1100 Subject: [PATCH 3/3] FIX: Update changelog --- Packages/com.unity.inputsystem/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index e48e3041a8..a2398d25cb 100755 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -12,6 +12,7 @@ however, it has to be formatted properly to pass verification tests. ### Fixed - Fixed `ArgumentNullException` when opening the Prefab Overrides window and selecting a component with an `InputAction`. +- Fixed `ArgumentOutOfRangeException` when a Player Input that has been auto switched is deleted, and then a Player Input Manager attempts to join a new player. ## [1.4.3] - 2022-09-23