Skip to content

Commit 2969a2c

Browse files
ShafranIvanIvan Shafran
and
Ivan Shafran
authored
Fix crash during animation (#553)
Co-authored-by: Ivan Shafran <ivan.shafran@factorialcomplexity.com>
1 parent 2b785cc commit 2969a2c

File tree

1 file changed

+5
-3
lines changed
  • sceneview/src/main/java/io/github/sceneview/node

1 file changed

+5
-3
lines changed

sceneview/src/main/java/io/github/sceneview/node/ModelNode.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,10 @@ open class ModelNode(
418418
}
419419

420420
private fun applyAnimations(frameTimeNanos: Long) {
421-
playingAnimations.forEach { (index, animation) ->
422-
if (animation.speed == 0f) return@forEach
421+
val iterator = playingAnimations.iterator()
422+
while (iterator.hasNext()) {
423+
val (index, animation) = iterator.next()
424+
if (animation.speed == 0f) continue
423425

424426
animator.let { animator ->
425427
val elapsedTimeSeconds = frameTimeNanos.intervalSeconds(animation.startTime)
@@ -434,7 +436,7 @@ open class ModelNode(
434436
animator.applyAnimation(index, animationTime)
435437

436438
if (!animation.loop && adjustedTimeSeconds >= animationDuration) {
437-
playingAnimations.remove(index)
439+
iterator.remove()
438440
}
439441
}
440442
}

0 commit comments

Comments
 (0)