Skip to content

Commit

Permalink
Merge pull request #2072 from davidkline-ms/nullRef2053
Browse files Browse the repository at this point in the history
handle case of no MotionControllerVisualizer singleton
  • Loading branch information
David Kline authored May 10, 2018
2 parents 64b18a7 + 06c677e commit 6a8760f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Assets/HoloToolkit/Common/Scripts/Singleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ public static bool IsInitialized
}
}

/// <summary>
/// Awake and OnEnable safe way to check if a Singleton is initialized.
/// </summary>
/// <returns>The value of the Singleton's IsInitialized property</returns>
public static bool ConfirmInitialized()
{
T access = Instance;
return IsInitialized;
}

/// <summary>
/// Base Awake method that sets the Singleton's unique instance.
/// Called by Unity when initializing a MonoBehaviour.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public InteractionSourceHandedness Handedness
protected virtual void OnEnable()
{
#if UNITY_WSA && UNITY_2017_2_OR_NEWER
if (!MotionControllerVisualizer.ConfirmInitialized())
{
// The motion controller visualizer singleton could not be found.
return;
}

// Look if the controller has loaded.
if (MotionControllerVisualizer.Instance.TryGetControllerModel(handedness, out ControllerInfo))
{
Expand Down

0 comments on commit 6a8760f

Please sign in to comment.