mastodon-sc / mastodon

Mastodon – a large-scale tracking and track-editing framework for large, multi-view images.
BSD 2-Clause "Simplified" License
66 stars 20 forks source link

Fix "File > Save Project As...". #273

Closed maarzt closed 5 months ago

maarzt commented 5 months ago

In Mastodon beta-27 there is an exception when user runs "File > Save Project As...".

The stack trace:

Exception in thread "AWT-EventQueue-0" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
    at java.awt.EventQueue.invokeAndWait(EventQueue.java:1331)
    at java.awt.EventQueue.invokeAndWait(EventQueue.java:1324)
    at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1353)
    at org.mastodon.mamut.io.ProjectSaver.saveProjectAs(ProjectSaver.java:159)
    at org.mastodon.mamut.io.ProjectActions.lambda$installAppActions$4(ProjectActions.java:114)
    at org.scijava.ui.behaviour.util.RunnableAction.actionPerformed(RunnableAction.java:47)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)

Why do we get thist exception?

The ProjectLoader.saveAs(...) is called from the AWT thread. But method's implementation expects the method not to be called from the AWT thread. Hence the exception.

Solution

This PR fixes the problem by creating a new "worker thread" which than executes the "save as" method.

@tinevez I'm not sure if you are happy with this solution. Feel free to solve the problem differently.