Skip to content

Commit 2e8f420

Browse files
committed
Cache child nodes before updating them to allow arbitrary adds / removals during update
1 parent eec379a commit 2e8f420

File tree

1 file changed

+5
-2
lines changed
  • kool-core/src/commonMain/kotlin/de/fabmax/kool/scene

1 file changed

+5
-2
lines changed

kool-core/src/commonMain/kotlin/de/fabmax/kool/scene/Node.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ open class Node(name: String? = null) : BaseReleasable() {
2727
val tags = Tags()
2828

2929
protected val mutChildren = mutableListOf<Node>()
30+
private val cachedChildren = mutableListOf<Node>()
3031
val children: List<Node> get() = mutChildren
3132

3233
/**
@@ -143,8 +144,10 @@ open class Node(name: String? = null) : BaseReleasable() {
143144

144145
bounds.batchUpdate {
145146
clear()
146-
for (i in mutChildren.lastIndex downTo 0) {
147-
val child = mutChildren[i]
147+
cachedChildren.clear()
148+
cachedChildren.addAll(mutChildren)
149+
for (i in cachedChildren.indices) {
150+
val child = cachedChildren[i]
148151
child.update(updateEvent)
149152
child.addBoundsToParentBounds(bounds)
150153
}

0 commit comments

Comments
 (0)