Skip to content

Commit 7982594

Browse files
authored
Merge pull request #10026 from MaxWang-MS/su_fix
Logging and SpatialAwarenessSurfaceTypes fix for Scene Understanding
2 parents cf87ff2 + 747bb1f commit 7982594

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

Assets/MRTK/Core/Definitions/SpatialAwareness/SpatialAwarenessSurfaceTypes.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ public enum SpatialAwarenessSurfaceTypes
4343
/// </remarks>
4444
Platform = 1 << 4,
4545

46-
// Insert additional surface types here.
47-
4846
/// <summary>
4947
/// A surface that does not fit one of the defined surface types.
5048
/// </summary>
@@ -53,16 +51,16 @@ public enum SpatialAwarenessSurfaceTypes
5351
/// <para>Background should not be confused with Unknown. There is sufficient data to
5452
/// classify the surface and it has been found to not correspond to a defined type.</para>
5553
/// </remarks>
56-
Background = 1 << 29,
54+
Background = 1 << 5,
5755

5856
/// <summary>
5957
/// A boundless world mesh.
6058
/// </summary>
61-
World = 1 << 30,
59+
World = 1 << 6,
6260

6361
/// <summary>
6462
/// Objects for which we have no observations
6563
/// </summary>
66-
Inferred = 1 << 31
64+
Inferred = 1 << 7
6765
}
6866
}

Assets/MRTK/Providers/Experimental/WindowsSceneUnderstanding/WindowsSceneUnderstandingObserver.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ public override void Enable()
166166
// Terminate the background thread when we stop in editor.
167167
cancelToken = cancelTokenSource.Token;
168168

169-
task = Task.Run(() => RunObserverAsync(cancelToken));
169+
task = Task.Run(() => RunObserverAsync(cancelToken)).ContinueWith(t =>
170+
{
171+
Debug.LogError($"{t.Exception.InnerException.GetType().Name}: {t.Exception.InnerException.Message} {t.Exception.InnerException.StackTrace}");
172+
}, TaskContinuationOptions.OnlyOnFaulted);
170173
#else
171174
IsEnabled = false;
172175
#endif // SCENE_UNDERSTANDING_PRESENT && UNITY_WSA
@@ -180,7 +183,7 @@ public override void Update()
180183
if (instantiationQueue.Count > 0)
181184
{
182185
// Make our new objects in batches and tell observers about it
183-
int batchCount = Math.Min(InstantiationBatchRate, instantiationQueue.Count);
186+
int batchCount = CreateGameObjects ? Math.Min(InstantiationBatchRate, instantiationQueue.Count) : instantiationQueue.Count;
184187

185188
for (int i = 0; i < batchCount; ++i)
186189
{
@@ -313,7 +316,10 @@ public IReadOnlyDictionary<int, SpatialAwarenessSceneObject> SceneObjects
313316
public void SaveScene(string filenamePrefix)
314317
{
315318
#if WINDOWS_UWP && SCENE_UNDERSTANDING_PRESENT
316-
Task.Run(() => SaveToFile(filenamePrefix));
319+
Task.Run(() => SaveToFile(filenamePrefix)).ContinueWith(t =>
320+
{
321+
Debug.LogError($"{t.Exception.InnerException.GetType().Name}: {t.Exception.InnerException.Message} {t.Exception.InnerException.StackTrace}");
322+
}, TaskContinuationOptions.OnlyOnFaulted);
317323
#else // WINDOWS_UWP && SCENE_UNDERSTANDING_PRESENT
318324
Debug.LogWarning("SaveScene() only supported at runtime! Ignoring request.");
319325
#endif // WINDOWS_UWP && SCENE_UNDERSTANDING_PRESENT
@@ -660,7 +666,7 @@ private async Task RunObserverAsync(CancellationToken cancellationToken)
660666

661667
case ObserverState.GetScene:
662668
observerState = ObserverState.Working;
663-
if (CreateGameObjects && instantiationQueue.Count > 0)
669+
while (CreateGameObjects && instantiationQueue.Count > 0)
664670
{
665671
await new WaitForUpdate();
666672
}
@@ -1315,13 +1321,13 @@ private Texture2D OcclusionTexture(byte[] textureBytes)
13151321
/// </summary>
13161322
private void CleanupInstantiatedSceneObjects()
13171323
{
1318-
if (observedObjectParent != null)
1324+
if (ObservedObjectParent != null)
13191325
{
1320-
int kidCount = observedObjectParent.transform.childCount;
1326+
int kidCount = ObservedObjectParent.transform.childCount;
13211327

13221328
for (int i = 0; i < kidCount; ++i)
13231329
{
1324-
UnityEngine.Object.Destroy(observedObjectParent.transform.GetChild(i).gameObject);
1330+
UnityEngine.Object.Destroy(ObservedObjectParent.transform.GetChild(i).gameObject);
13251331
}
13261332
}
13271333
}

0 commit comments

Comments
 (0)