Reputation: 1549
In my project I'm using a button that enables and disables spatial mapping/awareness. It works quite good, in 7 times out of 10. The following behaviour can be observed in the other 3 times. By disabling the spatial-map-mesh (polygones), they disappear to 90%. But 10% stays where it is. Repeated pressing of my button (dis/enable spatial mapping) does not help, the 10% just stays. Any suggestions what the reason for that behaivour could be?
Code Observer:
public void ToggleObservers()
{
if (SpatialAwarenessSystem == null) return;
// If running → stop "running"
if (_isObserverRunning)
{
SetVisualizationOfSpatialMapping(SpatialAwarenessMeshDisplayOptions.None);
SpatialAwarenessSystem.SuspendObservers();
_isObserverRunning = false;
// Disabling the whole system boosts performance ~+5fps
if (ShouldSpatialSystemBeDisabled)
SpatialAwarenessSystem.Disable();
}// Else start spatial mapping
else
{
SpatialAwarenessSystem.Enable();
SetVisualizationOfSpatialMapping(SpatialAwarenessMeshDisplayOptions.Visible);
SpatialAwarenessSystem.ResumeObservers();
_isObserverRunning = true;
}
}
Code Set Visualtization of Spatial Mapping:
public void SetVisualizationOfSpatialMapping(SpatialAwarenessMeshDisplayOptions option)
{
if (CoreServices.SpatialAwarenessSystem is IMixedRealityDataProviderAccess provider)
{
foreach (var observer in provider.GetDataProviders())
{
if (observer is IMixedRealitySpatialAwarenessMeshObserver meshObs)
{
meshObs.DisplayOption = option;
}
}
}
}
Edit: Bug Report on Github.
Upvotes: 0
Views: 1203
Reputation: 41
I also hit this issue. Until this is fixed in MRTK, you can patch this.
Edit this file:
MixedRealityToolkit.Providers\WindowsMixedReality\WindowsMixedRealitySpatialMeshObserver.cs
Find the suspend function, and add the code between // Begin Patch and // End Patch:
public override void Suspend()
{
#if UNITY_WSA
if (!IsRunning)
{
Debug.LogWarning("The Windows Mixed Reality spatial observer is currently stopped.");
return;
}
// UpdateObserver keys off of this value to stop observing.
IsRunning = false;
// Clear any pending work.
meshWorkQueue.Clear();
// Begin Patch
if (outstandingMeshObject != null)
{
ReclaimMeshObject(outstandingMeshObject);
outstandingMeshObject = null;
}
// End Patch
#endif // UNITY_WSA
}
Upvotes: 1
Reputation: 206
This appears to be a race condition where the mesh detected logic does not honor the state of the observer (suspended or resumed). Thanks for the issue @Perazim!
Upvotes: 1