Skip to content

Commit

Permalink
Quit if node setup times out
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Jun 28, 2024
1 parent 6947ef5 commit e3da262
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,13 @@ class Application implements EventTarget {
engine.start()
engine.systems*.scene = scene
scene.inputEventStream = inputEventStream
applicationStart?.apply(this, scene)

try {
applicationStart?.apply(this, scene)
}
catch (Exception ex) {
logger.error('An error occurred during application startup', ex)
}

engine.waitUntilStopped()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import groovy.transform.stc.ClosureParams
import groovy.transform.stc.SimpleType
import java.util.concurrent.CompletableFuture
import java.util.concurrent.CopyOnWriteArrayList
import java.util.concurrent.TimeUnit

/**
* An element of a scene, nodes are used to build and organize scene trees.
Expand Down Expand Up @@ -68,7 +69,9 @@ class Node<T extends Node> implements SceneEvents, Scriptable<T> {
// Allow it to process
var scene = getScene()
if (scene) {
addNodeAndChildren(scene, child).join()
addNodeAndChildren(scene, child)
.orTimeout(5, TimeUnit.SECONDS)
.join()
}

var childPosition = child.position
Expand Down Expand Up @@ -96,7 +99,7 @@ class Node<T extends Node> implements SceneEvents, Scriptable<T> {
.thenRunAsync { ->
scene.trigger(new NodeAddedEvent(node))
}
.thenCompose { _ ->
.thenComposeAsync { _ ->
var futures = node.children.collect { childNode -> addNodeAndChildren(scene, childNode) }

// Originally used the Groovy spread operator `*` but this would throw
Expand Down Expand Up @@ -254,7 +257,9 @@ class Node<T extends Node> implements SceneEvents, Scriptable<T> {
T removeChild(Node node) {

if (children.remove(node)) {
removeNodeAndChildren(scene, node).join()
removeNodeAndChildren(scene, node)
.orTimeout(5, TimeUnit.SECONDS)
.join()
node.parent = null
// TODO: Recalculate bounds
}
Expand Down

0 comments on commit e3da262

Please sign in to comment.