@@ -4162,13 +4162,40 @@ public void Devices_RemovingAndReaddingDevice_DoesNotAllocateMemory()
41624162 recorder . CollectFromAllThreads ( ) ;
41634163#endif
41644164
4165- // We expect a single allocation for each call to ReportNewInputDevice when there is one disconnected device
4166- //
4167- int numberOfRepeats = 2 ;
4168- int numberOfDisconnectedDevices = 1 ;
4169- int numberOfCallsToReportNewInputDevicePerRun = 2 ;
4170- int expectedAllocations = numberOfRepeats * numberOfDisconnectedDevices * numberOfCallsToReportNewInputDevicePerRun ;
4171- Assert . AreEqual ( expectedAllocations , recorder . sampleBlockCount ) ;
4165+ // No allocations are expected.
4166+ Assert . AreEqual ( 0 , recorder . sampleBlockCount ) ;
4167+ }
4168+
4169+ // Regression test to cover having null descriptor fields for a device. Some non-desktop gamepad device types do this.
4170+ [ Test ]
4171+ [ Category ( "Devices" ) ]
4172+ public void Devices_RemovingAndReaddingDeviceWithNullDescriptorFields_DoesNotThrow ( )
4173+ {
4174+ // InputDeviceDescription.ToJson writes empty string fields and not null values, whereas reporting a device via an incomplete description string will fully omit the fields.
4175+ string description = @"{
4176+ ""type"": ""Gamepad"",
4177+ ""product"": ""TestProduct""
4178+ }" ;
4179+
4180+ var deviceId = runtime . ReportNewInputDevice ( description ) ;
4181+ InputSystem . Update ( ) ;
4182+
4183+ // "Unplug" device.
4184+ var removeEvent1 = DeviceRemoveEvent . Create ( deviceId ) ;
4185+ InputSystem . QueueEvent ( ref removeEvent1 ) ;
4186+ InputSystem . Update ( ) ;
4187+
4188+ // "Plug" it back in.
4189+ deviceId = runtime . ReportNewInputDevice ( description ) ;
4190+ InputSystem . Update ( ) ;
4191+
4192+ // Repeat that sequence.
4193+ var removeEvent2 = DeviceRemoveEvent . Create ( deviceId ) ;
4194+ InputSystem . QueueEvent ( ref removeEvent2 ) ;
4195+ InputSystem . Update ( ) ;
4196+
4197+ runtime . ReportNewInputDevice ( description ) ;
4198+ InputSystem . Update ( ) ;
41724199 }
41734200
41744201 [ Test ]
0 commit comments