I basically want to be able to launch a new Javafx window (stage) after (and inside) my LWJGL/GLFW thread starts. I am basically doing:
Thread thread = new Thread(()->Platform.runLater(()->{
Stage stage = new Stage();
//Stage setup
stage.show();
}));
thread.start();
thread being my game thread.
But it never runs and I've tried a System.out.println()
inside Platform.runLater()
just to check it never runs.
Why does it never run and what can I do to fix it? Thanks.
EDIT: Just to clarify that the thread has definitely started and whatnot, if I do:
Thread thread = new Thread(()->{
System.out.println("Before Platform.runLater()");
Platform.runLater(()->System.out.println("Inside Platform.runLater()"));
System.out.println("After Platform.runLater()");
});
It outputs:
Before Platform.runLater()
After Platform.runLater()
Ok, I have found the solution to this!
If you run into any situation where all of your scenes end, the thread managing all of this will just peter out. To prevent this from happening, add this line before Platform.runLater
:
Platform.setImplicitExit(false);
Platform.runLater(()->System.out.println("Inside Platform.runLater()"));
So long as this runs before the last scene ends, it will keep the thread alive, and you will not run into the problem of runLater() failing!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With