Skip to content

Commit

Permalink
fix(RoomExtender_PlayAreaGizmo): null play area
Browse files Browse the repository at this point in the history
The play area gizmo of the RoomExtender looks up the play area in
`Awake` and later uses it when drawing the gizmo. The issue is that the
SDK Manager is not set up correctly at that point in time so the
returned play area is null, resulting in errors when trying to draw the
gizmo.

This fix makes sure `VRTK_SDKManager.instance` is always set up, no
matter when the getter is called. Additionally the play area gizmo
drawing method is changed to not throw any errors if the needed objects
weren't found in the `Awake` method. That method logs a warning already,
so the user is notified about the reason the gizmo isn't drawing.

This fix resolves #985.
  • Loading branch information
Christopher - Marcel Böddecker committed Mar 6, 2017
1 parent 6c8f887 commit 1dd32c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Expand Up @@ -41,8 +41,12 @@ protected virtual void OnDrawGizmosSelected()

private void DrawWireframe()
{
Vector3[] vertices = (playArea != null ? VRTK_SDK_Bridge.GetPlayAreaVertices(playArea.gameObject) : new Vector3[0]);
if (playArea == null || roomExtender == null)
{
return;
}

var vertices = VRTK_SDK_Bridge.GetPlayAreaVertices(playArea.gameObject);
if (vertices == null || vertices.Length == 0)
{
return;
Expand Down
31 changes: 20 additions & 11 deletions Assets/VRTK/Scripts/Utilities/VRTK_SDKManager.cs
Expand Up @@ -3,7 +3,6 @@ namespace VRTK
{
using UnityEngine;
#if UNITY_EDITOR
using UnityEngine.SceneManagement;
using UnityEditor;
using UnityEditor.Callbacks;
#endif
Expand Down Expand Up @@ -60,7 +59,23 @@ public class VRTK_SDKManager : MonoBehaviour
/// <summary>
/// The singleton instance to access the SDK Manager variables from.
/// </summary>
public static VRTK_SDKManager instance;
public static VRTK_SDKManager instance
{
get
{
if (_instance == null)
{
var sdkManager = FindObjectOfType<VRTK_SDKManager>();
if (sdkManager)
{
sdkManager.CreateInstance();
}
}

return _instance;
}
}
private static VRTK_SDKManager _instance;

[Tooltip("If this is true then the instance of the SDK Manager won't be destroyed on every scene load.")]
public bool persistOnLoad;
Expand Down Expand Up @@ -594,12 +609,6 @@ private static void AutoManageScriptingDefineSymbolsAndPopulateObjectReferences(

RemoveLegacyScriptingDefineSymbols();

var sdkManager = FindObjectOfType<VRTK_SDKManager>();
if (sdkManager)
{
sdkManager.CreateInstance();
}

if (instance != null && !instance.ManageScriptingDefineSymbols(false, false))
{
instance.PopulateObjectReferences(false);
Expand Down Expand Up @@ -664,9 +673,9 @@ private void SetupControllers()

private void CreateInstance()
{
if (instance == null)
if (_instance == null)
{
instance = this;
_instance = this;

string sdkErrorDescriptions = string.Join("\n- ", GetSimplifiedSDKErrorDescriptions());
if (!string.IsNullOrEmpty(sdkErrorDescriptions))
Expand All @@ -680,7 +689,7 @@ private void CreateInstance()
DontDestroyOnLoad(gameObject);
}
}
else if (instance != this)
else if (_instance != this)
{
Destroy(gameObject);
}
Expand Down

0 comments on commit 1dd32c6

Please sign in to comment.