Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javafx Platform.runLater never running

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()
like image 738
user2513924 Avatar asked Mar 27 '15 14:03

user2513924


1 Answers

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!

like image 150
Draque Thompson Avatar answered Oct 17 '22 07:10

Draque Thompson