what is the correct way of exiting the application when the user closes the main window? Where should I call shutdown-agents of Platform/exit ?
have you tried running that last one inside a fx/on-fx-thread
?https://github.com/cljfx/cljfx/blob/master/src/cljfx/platform.clj#L24
run-later and on-fx-thread are pretty similar 🙂
Just to give a bit more detail. When calling :on-close-request (fn [& _] (fx/on-fx-thread (javafx.application.Platform/exit)))
and setting up (javafx.application.Platform/setImplicitExit true)
inside my -main
Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Not on FX application thread; currentThread = JavaFX Application Thread
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:291)
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:446)
at javafx.stage.Window.setShowing(Window.java:1173)
at javafx.stage.Window.hide(Window.java:1199)
at com.sun.javafx.stage.WindowCloseRequestHandler.dispatchBubblingEvent(WindowCloseRequestHandler.java:45)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at com.sun.javafx.stage.WindowPeerListener.closing(WindowPeerListener.java:93)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:147)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.run(GlassWindowEventHandler.java:40)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.lambda$handleWindowEvent$4(GlassWindowEventHandler.java:176)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:412)
at com.sun.javafx.tk.quantum.GlassWindowEventHandler.handleWindowEvent(GlassWindowEventHandler.java:174)
at com.sun.glass.ui.Window.handleWindowEvent(Window.java:1351)
at com.sun.glass.ui.Window.notifyClose(Window.java:1251)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
at java.base/java.lang.Thread.run(Thread.java:832)
> java.lang.IllegalStateException: Not on FX application thread; currentThread = JavaFX Application Thread
wat
my thoughts exactly 😄
😂
I started seeing this kind of thread related issues when switching to fx/create-app
What I mean is I was forced to use on-fx-thread
for (.showDialog (DirectryChooser.) window)
argh, create-app...
I made a mistake introducing fx/wrap-async
it only creates problems
it's deprecated now, but it's in create-app
too...
You can set implicit exit to true to exit the platform on last window close, see https://github.com/cljfx/hn/blob/master/src/hn/core.clj#L49
I think it makes sense to call it in -main so it's not called during development
Do you use agents for cljfx's wrap async only?
If yes, I would suggest removing wrap-async, it creates more problems than solves
I already added (Platform/setImplicitExit true)
but the app is still not exiting after I closed the main window, maybe because some threads still running
I'm not using wrap-async
what I'm doing now as a workaround is setting stage with :on-close-request (fn [& _] (System/exit 0))
Looks fine, though I would expect calling platform/exit and shutdown-agents there to let jvm quit
tried that, but platform/exit doesn't work, it complains about not being called in the correct thread, tried with run-later but didn't work either