Skip to content

Commit b0169ec

Browse files
committed
Properly clean up coroutine
1 parent efb99a1 commit b0169ec

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Assets/MRTK/Core/Utilities/SceneContent/MixedRealitySceneContent.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ private enum AlignmentType
3535

3636
private Vector3 contentPosition = Vector3.zero;
3737
private const uint MaxEditorFrameWaitCount = 5;
38+
private Coroutine initializeSceneContentWithDelay;
3839

3940
private void Awake()
4041
{
@@ -44,7 +45,15 @@ private void Awake()
4445
}
4546

4647
// Init the content height on non-XR platforms
47-
StartCoroutine(InitializeSceneContentWithDelay());
48+
initializeSceneContentWithDelay = StartCoroutine(InitializeSceneContentWithDelay());
49+
}
50+
51+
private void OnDestroy()
52+
{
53+
if (initializeSceneContentWithDelay != null)
54+
{
55+
StopCoroutine(initializeSceneContentWithDelay);
56+
}
4857
}
4958

5059
// Not waiting often caused the camera's position to be incorrect at this point. This seems like a Unity bug.
@@ -64,6 +73,8 @@ private IEnumerator InitializeSceneContentWithDelay()
6473
}
6574

6675
InitializeSceneContent();
76+
77+
initializeSceneContentWithDelay = null;
6778
}
6879

6980

0 commit comments

Comments
 (0)