From 12e62c6742d6e13fdeba26c0211c52ed38baf898 Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Mon, 28 Sep 2020 14:29:16 -0400 Subject: [PATCH] Fixed issues around errors when starting and stopping playmode in editor (#668) * Fixed issues around errors when starting and stopping playmode in editor * updated sdk checkout --- .../BaseMixedRealitySpatialMeshObserver.cs | 10 +++++----- Runtime/Services/MixedRealityToolkit.cs | 10 +--------- .../MixedRealitySpatialAwarenessSystem.cs | 9 +++------ 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/Runtime/Providers/SpatialObservers/BaseMixedRealitySpatialMeshObserver.cs b/Runtime/Providers/SpatialObservers/BaseMixedRealitySpatialMeshObserver.cs index 9f6b323a8..adc5189d9 100644 --- a/Runtime/Providers/SpatialObservers/BaseMixedRealitySpatialMeshObserver.cs +++ b/Runtime/Providers/SpatialObservers/BaseMixedRealitySpatialMeshObserver.cs @@ -134,10 +134,8 @@ public override void Disable() // Disable any spatial meshes we might have. foreach (var meshObject in spatialMeshObjects.Values) { - if (meshObject.GameObject != null) - { - meshObject.GameObject.SetActive(false); - } + Debug.Assert(meshObject.GameObject != null); + meshObject.GameObject.SetActive(false); } } @@ -152,7 +150,7 @@ public override void Destroy() meshObject.GameObject.Destroy(); } - spatialMeshObjects.Clear(); + Debug.Assert(spatialMeshObjects.Count == 0); lock (spatialMeshObjectPool) { @@ -161,6 +159,8 @@ public override void Destroy() var meshObject = spatialMeshObjectPool.Pop(); meshObject.GameObject.Destroy(); } + + Debug.Assert(spatialMeshObjectPool.Count == 0); } } diff --git a/Runtime/Services/MixedRealityToolkit.cs b/Runtime/Services/MixedRealityToolkit.cs index d1e3953aa..522f27917 100644 --- a/Runtime/Services/MixedRealityToolkit.cs +++ b/Runtime/Services/MixedRealityToolkit.cs @@ -673,15 +673,7 @@ private void Awake() if (IsInitialized && instance != this) { - if (Application.isEditor) - { - DestroyImmediate(gameObject); - } - else - { - Destroy(gameObject); - } - + gameObject.Destroy(); Debug.LogWarning($"Trying to instantiate a second instance of the {nameof(MixedRealityToolkit)}. Additional Instance was destroyed"); } else if (!IsInitialized) diff --git a/Runtime/Services/SpatialAwarenessSystem/MixedRealitySpatialAwarenessSystem.cs b/Runtime/Services/SpatialAwarenessSystem/MixedRealitySpatialAwarenessSystem.cs index 1174e2945..1ce2625f3 100644 --- a/Runtime/Services/SpatialAwarenessSystem/MixedRealitySpatialAwarenessSystem.cs +++ b/Runtime/Services/SpatialAwarenessSystem/MixedRealitySpatialAwarenessSystem.cs @@ -202,25 +202,22 @@ public override void Destroy() if (spatialAwarenessParent != null) { spatialAwarenessParent.transform.DetachChildren(); + spatialAwarenessParent.Destroy(); } - spatialAwarenessParent.Destroy(); - // Detach the mesh objects (they are to be cleaned up by the observer) and cleanup the parent if (meshParent != null) { meshParent.transform.DetachChildren(); + meshParent.Destroy(); } - meshParent.Destroy(); - // Detach the surface objects (they are to be cleaned up by the observer) and cleanup the parent if (surfaceParent != null) { surfaceParent.transform.DetachChildren(); + surfaceParent.Destroy(); } - - surfaceParent.Destroy(); } #region Mesh Events