Skip to content

Commit 911d2dd

Browse files
author
lawwong
committed
Add null check
1 parent de42210 commit 911d2dd

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/VIUSyntheticDevice.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,19 @@ public VIUSyntheticDevice GetDevice(int roleValue)
209209

210210
private VIUSyntheticDevice AddDevice(ViveRole.IMap map, int roleValue)
211211
{
212-
VIUSyntheticDevice device;
213212
try
214213
{
215-
device = InputSystem.AddDevice(new InputDeviceDescription()
214+
var device = InputSystem.AddDevice(new InputDeviceDescription()
216215
{
217216
interfaceName = layoutName,
218217
manufacturer = "HTC ViveSoftware",
219218
}) as VIUSyntheticDevice;
219+
220+
if (device == null)
221+
{
222+
Debug.LogError("[VIUSyntheticDevice] InputSystem.AddDevice(InputDeviceDescription) failed!");
223+
return null;
224+
}
220225

221226
InputSystem.AddDeviceUsage(device, map.RoleValueInfo.GetNameByRoleValue(roleValue));
222227
if (leftRgx.IsMatch(layoutName))
@@ -227,14 +232,15 @@ private VIUSyntheticDevice AddDevice(ViveRole.IMap map, int roleValue)
227232
{
228233
InputSystem.AddDeviceUsage(device, CommonUsages.RightHand);
229234
}
235+
236+
device.ctrlState = ViveInput.GetState(map.RoleValueInfo.RoleEnumType, roleValue);
237+
return device;
230238
}
231239
catch (Exception e)
232240
{
233241
Debug.LogException(e);
234242
return null;
235243
}
236-
device.ctrlState = ViveInput.GetState(map.RoleValueInfo.RoleEnumType, roleValue);
237-
return device;
238244
}
239245

240246
private static void ResumeDevice(InputDevice device)

0 commit comments

Comments
 (0)