Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

Commit

Permalink
Fixed editor crash in play mode with spatial mesh observer, we now wa…
Browse files Browse the repository at this point in the history
…it until the mesh subsystem is running (#22)
  • Loading branch information
StephenHodgson authored May 12, 2019
1 parent 2f6e51c commit 89ca225
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions SpatialObservers/LuminSpatialMeshObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
using UnityEngine.XR.MagicLeap;
using XRTK.Definitions.SpatialAwarenessSystem;
using XRTK.Utilities;
using XRTK.Utilities.Async;

#if UNITY_EDITOR
using UnityEditor.XR.MagicLeap.Remote;
#endif // UNITY_EDITOR
#endif // PLATFORM_LUMIN

namespace XRTK.Lumin.SpatialObservers
Expand Down Expand Up @@ -43,10 +48,12 @@ public LuminSpatialMeshObserver(string name, uint priority, BaseMixedRealitySpat

#region IMixedRealityService implementation

public override void Initialize()
public override async void Initialize()
{
if (!Application.isPlaying || meshSubsystem != null) { return; }

await MagicLeapRemoteManager.isInitialized.WaitUntil(initialized => initialized);

descriptors.Clear();
SubsystemManager.GetSubsystemDescriptors(descriptors);

Expand Down Expand Up @@ -87,7 +94,12 @@ public override void Update()
base.Update();

// Only update the observer if it is running.
if (!Application.isPlaying || !IsRunning) { return; }
if (!IsRunning ||
meshSubsystem == null ||
!Application.isPlaying)
{
return;
}

// and If enough time has passed since the previous observer update
if (!(Time.time - lastUpdated >= UpdateInterval)) { return; }
Expand Down Expand Up @@ -132,30 +144,31 @@ protected override void OnDispose(bool finalizing)
#region IMixedRealitySpatialMeshObserver implementation

/// <inheritdoc/>
public override void StartObserving()
public override async void StartObserving()
{
if (IsRunning)
{
return;
}

base.StartObserving();

await meshSubsystem.WaitUntil(subsystem => subsystem != null);

meshSubsystem.Start();

// We want the first update immediately.
lastUpdated = 0;

base.StartObserving();
}

public override void StopObserving()
{
if (!IsRunning)
{
return;

}

meshSubsystem.Stop();
meshSubsystem?.Stop();

base.StopObserving();
}
Expand Down

0 comments on commit 89ca225

Please sign in to comment.