Skip to content

Commit 35ec3e5

Browse files
authored
FIX: canRunInBackground not set correctly for VR devices (#1233).
1 parent 93088fd commit 35ec3e5

File tree

4 files changed

+58
-5
lines changed

4 files changed

+58
-5
lines changed

Assets/Tests/InputSystem/CoreTests_Devices.cs

+55
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,61 @@ public void Devices_QueryTheirEnabledStateFromRuntime()
17681768
Assert.That(receivedQueryEnabledStateCommand, Is.Null);
17691769
}
17701770

1771+
[Test]
1772+
[Category("Devices")]
1773+
public unsafe void Devices_CanMarkDeviceAsBeingAbleToRunInBackground()
1774+
{
1775+
var device1Id = runtime.ReportNewInputDevice<Gamepad>();
1776+
var device2Id = runtime.ReportNewInputDevice<Mouse>();
1777+
1778+
var receivedCanRunInBackgroundForDevice1 = false;
1779+
var receivedCanRunInBackgroundForDevice2 = false;
1780+
1781+
runtime.SetDeviceCommandCallback(device1Id,
1782+
(id, command) =>
1783+
{
1784+
if (command->type != QueryCanRunInBackground.Type)
1785+
return InputDeviceCommand.GenericFailure;
1786+
1787+
Assert.That(id, Is.EqualTo(device1Id));
1788+
Assert.That(command->payloadSizeInBytes, Is.EqualTo(UnsafeUtility.SizeOf<bool>()));
1789+
1790+
receivedCanRunInBackgroundForDevice1 = true;
1791+
((QueryCanRunInBackground*)command)->canRunInBackground = true;
1792+
return InputDeviceCommand.GenericSuccess;
1793+
});
1794+
runtime.SetDeviceCommandCallback(device2Id,
1795+
(id, command) =>
1796+
{
1797+
if (command->type != QueryCanRunInBackground.Type)
1798+
return InputDeviceCommand.GenericFailure;
1799+
1800+
Assert.That(id, Is.EqualTo(device2Id));
1801+
Assert.That(command->payloadSizeInBytes, Is.EqualTo(UnsafeUtility.SizeOf<bool>()));
1802+
1803+
receivedCanRunInBackgroundForDevice2 = true;
1804+
((QueryCanRunInBackground*)command)->canRunInBackground = false;
1805+
return InputDeviceCommand.GenericSuccess;
1806+
});
1807+
1808+
InputSystem.Update();
1809+
1810+
// Just adding the device should not have triggered a query for canRunInBackground.
1811+
Assert.That(receivedCanRunInBackgroundForDevice1, Is.False);
1812+
Assert.That(receivedCanRunInBackgroundForDevice2, Is.False);
1813+
1814+
var device1 = InputSystem.GetDeviceById(device1Id);
1815+
var device2 = InputSystem.GetDeviceById(device2Id);
1816+
1817+
var device1CanRunInBackground = device1.canRunInBackground;
1818+
var device2CanRunInBackground = device2.canRunInBackground;
1819+
1820+
Assert.That(receivedCanRunInBackgroundForDevice1, Is.True);
1821+
Assert.That(receivedCanRunInBackgroundForDevice2, Is.True);
1822+
Assert.That(device1CanRunInBackground, Is.True);
1823+
Assert.That(device2CanRunInBackground, Is.False);
1824+
}
1825+
17711826
[Test]
17721827
[Category("Devices")]
17731828
public void Devices_NativeDevicesAreFlaggedAsSuch()

Packages/com.unity.inputsystem/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ however, it has to be formatted properly to pass verification tests.
1919
### Fixed
2020

2121
- Fixed precompiled layouts such as `FastKeyboard` leading to build time regressions with il2cpp (case 1283676).
22+
- Fixed `InputDevice.canRunInBackground` not being correctly set for VR devices (thus not allowing them to receive input while the application is not focused).
2223
- Fixed `InputUser.OnEvent` and `RebindingOperation.OnEvent` exhibiting bad performance profiles and leading to multi-millisecond input update times (case 1253371).
2324
* In our own measurements, `InputUser.OnEvent` is >9 times faster than before and `RebindingOperation.OnEvent` is ~2.5 times faster.
2425
- Fixed PS4 controller not recognized on Mac when connected over Bluetooth ([case 1286449](https://issuetracker.unity3d.com/issues/input-system-dualshock-4-zct1e-dualshock-2-v1-devices-are-not-fully-recognised-over-bluetooth)).

Packages/com.unity.inputsystem/InputSystem/Devices/Commands/InputDeviceCommand.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ public struct InputDeviceCommand : IInputDeviceCommandInfo
5252
[FieldOffset(0)] public FourCC type;
5353
[FieldOffset(4)] public int sizeInBytes;
5454

55-
public int payloadSizeInBytes
56-
{
57-
get { return sizeInBytes - kBaseCommandSize; }
58-
}
55+
public int payloadSizeInBytes => sizeInBytes - kBaseCommandSize;
5956

6057
public unsafe void* payloadPtr
6158
{

Packages/com.unity.inputsystem/InputSystem/Devices/Commands/QueryCanRunInBackground.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public struct QueryCanRunInBackground : IInputDeviceCommandInfo
1212
{
1313
public static FourCC Type => new FourCC('Q', 'R', 'I', 'B');
1414

15-
internal const int kSize = InputDeviceCommand.kBaseCommandSize;
15+
internal const int kSize = InputDeviceCommand.kBaseCommandSize + sizeof(bool);
1616

1717
[FieldOffset(0)]
1818
public InputDeviceCommand baseCommand;

0 commit comments

Comments
 (0)