Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle case of no MotionControllerVisualizer singleton #2072

Merged
merged 3 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't in the master branch already?

Any other singleton changes we didn't have?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it wasn't. i will look and open a PR if i see any more missing code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the same thing!

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