Skip to content

Commit b499db7

Browse files
authored
Merge pull request #7111 from keveleigh/null-prop
Fix some Unity object null propagation and other warnings
2 parents 599167f + 3a572d5 commit b499db7

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

Assets/MixedRealityToolkit.Services/InputSimulation/SimulatedGestureHand.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class SimulatedGestureHand : SimulatedHand
3232
private Vector3 cumulativeDelta = Vector3.zero;
3333
private MixedRealityPose currentGripPose = MixedRealityPose.ZeroIdentity;
3434

35-
private Vector3 navigationDelta => new Vector3(
35+
private Vector3 NavigationDelta => new Vector3(
3636
Mathf.Clamp(cumulativeDelta.x, -1.0f, 1.0f) * currentRailsUsed.x,
3737
Mathf.Clamp(cumulativeDelta.y, -1.0f, 1.0f) * currentRailsUsed.y,
3838
Mathf.Clamp(cumulativeDelta.z, -1.0f, 1.0f) * currentRailsUsed.z);
@@ -59,7 +59,12 @@ private void EnsureProfileSettings()
5959
}
6060
initializedFromProfile = true;
6161

62-
var gestureProfile = CoreServices.InputSystem?.InputSystemProfile?.GesturesProfile;
62+
MixedRealityGesturesProfile gestureProfile = null;
63+
MixedRealityInputSystemProfile inputSystemProfile = CoreServices.InputSystem?.InputSystemProfile;
64+
if (inputSystemProfile != null)
65+
{
66+
gestureProfile = inputSystemProfile.GesturesProfile;
67+
}
6368
if (gestureProfile != null)
6469
{
6570
for (int i = 0; i < gestureProfile.Gestures.Length; i++)
@@ -288,15 +293,15 @@ private void UpdateNavigation()
288293
if (navigationInProgress)
289294
{
290295
UpdateNavigationRails();
291-
CoreServices.InputSystem?.RaiseGestureUpdated(this, navigationAction, navigationDelta);
296+
CoreServices.InputSystem?.RaiseGestureUpdated(this, navigationAction, NavigationDelta);
292297
}
293298
}
294299

295300
private bool TryCompleteNavigation()
296301
{
297302
if (navigationInProgress)
298303
{
299-
CoreServices.InputSystem?.RaiseGestureCompleted(this, navigationAction, navigationDelta);
304+
CoreServices.InputSystem?.RaiseGestureCompleted(this, navigationAction, NavigationDelta);
300305
navigationInProgress = false;
301306
return true;
302307
}

Assets/MixedRealityToolkit.Services/InputSystem/MixedRealityInputSystem.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ private void CreateDataProviders()
248248
MixedRealityInputSystemProfile profile = ConfigurationProfile as MixedRealityInputSystemProfile;
249249

250250
// If the system gets disabled, the gaze provider is destroyed.
251-
// Ensure that it gets recreated on when reenabled.
252-
if (GazeProvider == null)
251+
// Ensure that it gets recreated on when re-enabled.
252+
if (GazeProvider == null && profile != null)
253253
{
254-
InstantiateGazeProvider(profile?.PointerProfile);
254+
InstantiateGazeProvider(profile.PointerProfile);
255255
}
256256

257257
if ((GetDataProviders().Count == 0) && (profile != null))
@@ -272,7 +272,7 @@ private void CreateDataProviders()
272272

273273
private void InstantiateGazeProvider(MixedRealityPointerProfile pointerProfile)
274274
{
275-
if (pointerProfile?.GazeProviderType?.Type != null)
275+
if (pointerProfile != null && pointerProfile.GazeProviderType?.Type != null)
276276
{
277277
GazeProvider = CameraCache.Main.gameObject.EnsureComponent(pointerProfile.GazeProviderType.Type) as IMixedRealityGazeProvider;
278278
GazeProvider.GazeCursorPrefab = pointerProfile.GazeCursorPrefab;
@@ -318,7 +318,7 @@ public override void Disable()
318318
GazeProvider = null;
319319
}
320320

321-
foreach(var provider in GetDataProviders<IMixedRealityInputDeviceManager>())
321+
foreach (var provider in GetDataProviders<IMixedRealityInputDeviceManager>())
322322
{
323323
if (provider != null)
324324
{
@@ -991,15 +991,20 @@ public void RaiseFocusExit(IMixedRealityPointer pointer, GameObject unfocusedObj
991991
public void RaisePointerDown(IMixedRealityPointer pointer, MixedRealityInputAction inputAction, Handedness handedness = Handedness.None, IMixedRealityInputSource inputSource = null)
992992
{
993993
// Only lock the object if there is a grabbable above in the hierarchy
994-
Transform currentObject = pointer.Result?.Details.Object?.transform;
994+
Transform currentObject = null;
995+
GameObject currentGameObject = pointer.Result?.Details.Object;
996+
if (currentGameObject != null)
997+
{
998+
currentObject = currentGameObject.transform;
999+
}
9951000
IMixedRealityPointerHandler ancestorPointerHandler = null;
996-
while(currentObject != null && ancestorPointerHandler == null)
1001+
while (currentObject != null && ancestorPointerHandler == null)
9971002
{
998-
foreach(var component in currentObject.GetComponents<Component>())
1003+
foreach (var component in currentObject.GetComponents<Component>())
9991004
{
10001005
if (component is IMixedRealityPointerHandler)
10011006
{
1002-
ancestorPointerHandler = (IMixedRealityPointerHandler) component;
1007+
ancestorPointerHandler = (IMixedRealityPointerHandler)component;
10031008
break;
10041009
}
10051010
}

Assets/MixedRealityToolkit/Providers/UnityInput/MouseController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void Update()
9292
if (Interactions[i].InputType == DeviceInputType.SpatialPointer)
9393
{
9494
// Spatial pointer raises Pose events
95-
MixedRealityPose controllerPose = MixedRealityPose.ZeroIdentity;
95+
controllerPose = MixedRealityPose.ZeroIdentity;
9696
controllerPose.Rotation = Quaternion.Euler(mouseDelta);
9797
Interactions[i].PoseData = controllerPose;
9898

0 commit comments

Comments
 (0)