Guard against nested event loop exceptions

This commit is contained in:
crschnick 2025-03-20 12:15:12 +00:00
parent d4a713f29b
commit 8c51eac399
2 changed files with 23 additions and 4 deletions

View file

@ -84,7 +84,7 @@ public class AppDialog {
var transition = new PauseTransition(Duration.millis(200));
transition.setOnFinished(e -> {
if (wait) {
Platform.exitNestedEventLoop(key, null);
PlatformThread.exitNestedEventLoop(key);
}
});
transition.play();
@ -95,7 +95,7 @@ public class AppDialog {
}
});
if (wait) {
Platform.enterNestedEventLoop(key);
PlatformThread.enterNestedEventLoop(key);
waitForDialogClose(o);
}
}

View file

@ -274,6 +274,25 @@ public class PlatformThread {
return true;
}
public static void enterNestedEventLoop(Object key) {
try {
Platform.enterNestedEventLoop(key);
} catch (IllegalStateException ex) {
// We might be in an animation or layout call
ErrorEvent.fromThrowable(ex).omit().expected().handle();
}
}
public static void exitNestedEventLoop(Object key) {
try {
Platform.exitNestedEventLoop(key, null);
} catch (IllegalArgumentException ex) {
// The event loop might have died somehow
// Or we passed an invalid key
ErrorEvent.fromThrowable(ex).omit().expected().handle();
}
}
public static void runNestedLoopIteration() {
if (!Platform.canStartNestedEventLoop()) {
return;
@ -281,9 +300,9 @@ public class PlatformThread {
var key = new Object();
Platform.runLater(() -> {
Platform.exitNestedEventLoop(key, null);
exitNestedEventLoop(key);
});
Platform.enterNestedEventLoop(key);
enterNestedEventLoop(key);
}
public static void runLaterIfNeeded(Runnable r) {