Skip to content

Commit

Permalink
Merge pull request #2078 from keveleigh/SolverNullRef
Browse files Browse the repository at this point in the history
[May18] Fixes SolverBodyLock potential null ref
  • Loading branch information
David Kline authored May 11, 2018
2 parents 0adda87 + 344e3d1 commit c9d0ea6
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions Assets/HoloToolkit/Utilities/Scripts/Solvers/SolverBodyLock.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
//

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace HoloToolkit.Unity
{
/// <summary>
/// SolverBodyLock provides a solver that follows the TrackedObject/TargetTransform. Adjusting "LerpTime"
/// properties changes how quickly the object moves to the TracketObject/TargetTransform's position.
/// properties changes how quickly the object moves to the TrackedObject/TargetTransform's position.
/// </summary>
public class SolverBodyLock : Solver
{
Expand All @@ -28,22 +25,20 @@ public enum OrientationReference
}
#endregion


#region public members
[Tooltip("The desired orientation of this object. Default sets the object to face the TrackedObject/TargetTransform. CameraFacing sets the object to always face the user.")]
public OrientationReference Orientation = OrientationReference.Default;
[Tooltip("XYZ offset for this object in relation to the TrackedObject/TargetTransform")]
public Vector3 offset;
[Tooltip("RotationTether snaps the object to be in front of TrackedObject regardless of the object's local rotation.")]
public bool RotationTether = false;
[Tooltip("TetherAngleSteps is the divison of steps this object can tether to. Higher the number, the more snapple steps.")]
[Tooltip("TetherAngleSteps is the division of steps this object can tether to. Higher the number, the more snapple steps.")]
[Range(4, 12)]
public int TetherAngleSteps = 6;
#endregion

public override void SolverUpdate()
{
Vector3 desiredPos = base.solverHandler.TransformTarget != null ? base.solverHandler.TransformTarget.position + offset : Vector3.zero;
Quaternion desiredRot = Quaternion.identity;

if (RotationTether)
Expand All @@ -62,10 +57,10 @@ public override void SolverUpdate()
desiredRot = Quaternion.Euler(0f, tetherYRotation, 0f);
}

desiredPos = solverHandler.TransformTarget.position + (desiredRot * offset);
Vector3 desiredPos = solverHandler.TransformTarget != null ? solverHandler.TransformTarget.position + (desiredRot * offset) : Vector3.zero;

this.GoalPosition = desiredPos;
this.GoalRotation = desiredRot;
GoalPosition = desiredPos;
GoalRotation = desiredRot;

UpdateWorkingPosToGoal();
UpdateWorkingRotToGoal();
Expand Down

0 comments on commit c9d0ea6

Please sign in to comment.