Skip to content

Commit f1ed49f

Browse files
authored
Merge pull request #9463 from robertos/progress-bug
Ensure async operations on progress indicators don't wait on animations if the object is hidden
2 parents 365e2b6 + 7690dc4 commit f1ed49f

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

Assets/MRTK/SDK/Features/UX/Scripts/ProgressIndicators/ProgressIndicatorObjectDisplay.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public async Task OpenAsync()
100100

101101
float startTime = Time.unscaledTime;
102102
float openScale = 0f;
103-
while (openScale < 1)
103+
while (openScale < 1 && isActiveAndEnabled)
104104
{
105105
openScale = openCurve.Evaluate(Time.unscaledTime - startTime);
106106
scaleTargetObject.transform.localScale = Vector3.one * currentScale * openScale;
@@ -133,7 +133,7 @@ public async Task CloseAsync()
133133

134134
float startTime = Time.unscaledTime;
135135
float closeScale = 1f;
136-
while (closeScale > 0)
136+
while (closeScale > 0 && isActiveAndEnabled)
137137
{
138138
closeScale = closeCurve.Evaluate(Time.unscaledTime - startTime);
139139
scaleTargetObject.transform.localScale = Vector3.one * currentScale * closeScale;

Assets/MRTK/SDK/Features/UX/Scripts/ProgressIndicators/ProgressIndicatorOrbsRotator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public async Task CloseAsync()
8585

8686
StopOrbs();
8787

88-
while (!hasAnimationFinished)
88+
while (!hasAnimationFinished && isActiveAndEnabled)
8989
{
9090
await Task.Yield();
9191
}

Assets/MRTK/Tests/PlayModeTests/LoadingIndicatorTests.cs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,38 @@ public IEnumerator TestOpenCloseRotatingOrbsPrefab()
9393
yield return null;
9494
}
9595

96-
private async Task TestOpenCloseProgressIndicatorAsync(GameObject progressIndicatorObject, IProgressIndicator progressIndicator, float timeOpen = 2f)
96+
/// <summary>
97+
/// Tests that prefab finishes closing after being disabled at runtime.
98+
/// </summary>
99+
[UnityTest]
100+
public IEnumerator TestHideBeforeClosingRotatingOrbsPrefab()
101+
{
102+
GameObject progressIndicatorObject;
103+
IProgressIndicator progressIndicator;
104+
InstantiatePrefab(progressIndicatorRotatingOrbsPrefabPath, out progressIndicatorObject, out progressIndicator);
105+
Task testTask = TestOpenCloseProgressIndicatorAsync(progressIndicatorObject, progressIndicator, 3f, hideAfterOpening: true);
106+
107+
// Wait a maximum time before considering the progress bar as stuck
108+
float timeStarted = Time.time;
109+
const float timeout = 5.0f;
110+
while (!testTask.IsCompleted)
111+
{
112+
if (Time.time < timeStarted + timeout)
113+
{
114+
yield return null;
115+
}
116+
else
117+
{
118+
Assert.Fail("The progress bar is stuck closing.");
119+
}
120+
}
121+
122+
// clean up
123+
GameObject.Destroy(progressIndicatorObject);
124+
yield return null;
125+
}
126+
127+
private async Task TestOpenCloseProgressIndicatorAsync(GameObject progressIndicatorObject, IProgressIndicator progressIndicator, float timeOpen = 2f, bool hideAfterOpening = false)
97128
{
98129
// Deactivate the progress indicator
99130
progressIndicatorObject.SetActive(false);
@@ -111,6 +142,12 @@ private async Task TestOpenCloseProgressIndicatorAsync(GameObject progressIndica
111142
// Make sure it's actually open
112143
Assert.True(progressIndicator.State == ProgressIndicatorState.Open, "Progress indicator was not open after open async call: " + progressIndicator.State);
113144

145+
// Hide the gameObject if requested
146+
if (hideAfterOpening)
147+
{
148+
progressIndicatorObject.SetActive(false);
149+
}
150+
114151
// Make sure we can set its progress and message while open
115152
// Also make sure we can set progress to a value greater than 1 without blowing anything up
116153
float timeStarted = Time.time;

0 commit comments

Comments
 (0)