Skip to content

Commit 721d118

Browse files
committed
Remove while loop from animation code to prevent possible hang
1 parent 53a4f91 commit 721d118

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Source/RunActivity/Viewer3D/AnimatedPart.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,16 @@ public void SetFrameCycle(float frame)
130130
public void SetFrameWrap(float frame)
131131
{
132132
// Wrap the frame around 0-MaxFrame without hanging when MaxFrame=0.
133-
while (MaxFrame > 0 && frame < 0) frame += MaxFrame;
134-
if (frame < 0) frame = 0;
135-
frame %= MaxFrame;
133+
if (MaxFrame > 0)
134+
{
135+
frame %= MaxFrame;
136+
// If frame was negative (eg: animation run in reverse), it will still be negative
137+
// and needs one additional offset by MaxFrame to be in the correct range
138+
if (frame < 0)
139+
frame += MaxFrame;
140+
}
141+
else if (frame < 0)
142+
frame = 0;
136143
SetFrame(frame);
137144
}
138145

0 commit comments

Comments
 (0)