Skip to content

Commit

Permalink
#1725 resolves issue with JavaFX errors during application shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
sheirerd committed Dec 31, 2023
1 parent d48ff50 commit 6193e63
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/main/java/io/github/dsheirer/gui/JavaFxWindowManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.github.dsheirer.monitor.StatusBox;
import io.github.dsheirer.preference.UserPreferences;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.annotation.Resource;
import javafx.application.Application;
import javafx.application.Platform;
Expand All @@ -53,6 +54,10 @@
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
* Java FX window manager. Handles all secondary Java FX windows that are used within this primarily
* Swing application.
Expand Down Expand Up @@ -96,6 +101,7 @@ public class JavaFxWindowManager extends Application
private Stage mPlaylistStage;
private Stage mUserPreferencesStage;
private Stage mRecordingViewerStage;
private List<Stage> mStages = new ArrayList<>();

/**
* Constructs an instance. Note: this constructor is used for Swing applications.
Expand Down Expand Up @@ -154,7 +160,27 @@ public void shutdown()
{
MyEventBus.getGlobalEventBus().unregister(this);
mUserPreferences.getJavaFxPreferences().clearStageMonitors();
Platform.exit();

Platform.runLater(() ->
{
Iterator<Stage> it = mStages.iterator();

while(it.hasNext())
{
try
{
it.next().close();
}
catch(Throwable t)
{
//Do nothing ... we're shutting down
}

it.remove();
}

Platform.exit();
});
}

public CalibrationDialog getCalibrationDialog(UserPreferences userPreferences)
Expand All @@ -173,6 +199,7 @@ public Stage getRecordingViewerStage()
mRecordingViewerStage = new Stage();
mRecordingViewerStage.setTitle("sdrtrunk - Message Recording Viewer (.bits)");
mRecordingViewerStage.setScene(scene);
mStages.add(mRecordingViewerStage);
mUserPreferences.getJavaFxPreferences().monitor(mRecordingViewerStage, STAGE_MONITOR_KEY_RECORDING_VIEWER);
}

Expand All @@ -197,6 +224,7 @@ public Stage getIconManagerStage()
mIconManagerStage = new Stage();
mIconManagerStage.setTitle("sdrtrunk - Icon Manager");
mIconManagerStage.setScene(scene);
mStages.add(mIconManagerStage);
mUserPreferences.getJavaFxPreferences().monitor(mIconManagerStage, STAGE_MONITOR_KEY_ICON_MANAGER_EDITOR);
}

Expand Down Expand Up @@ -239,6 +267,7 @@ public Stage getJmbeEditorStage()
mJmbeEditorStage = new Stage();
mJmbeEditorStage.setTitle("sdrtrunk - JMBE Library Updater");
mJmbeEditorStage.setScene(scene);
mStages.add(mJmbeEditorStage);
mUserPreferences.getJavaFxPreferences().monitor(mJmbeEditorStage, STAGE_MONITOR_KEY_JMBE_EDITOR);
}

Expand Down Expand Up @@ -269,6 +298,7 @@ private Stage getPlaylistStage()
mPlaylistStage = new Stage();
mPlaylistStage.setTitle("sdrtrunk - Playlist Editor");
mPlaylistStage.setScene(scene);
mStages.add(mPlaylistStage);
mUserPreferences.getJavaFxPreferences().monitor(mPlaylistStage, STAGE_MONITOR_KEY_PLAYLIST_EDITOR);
}

Expand Down Expand Up @@ -313,6 +343,7 @@ private Stage getUserPreferencesStage()
mUserPreferencesStage = new Stage();
mUserPreferencesStage.setTitle("sdrtrunk - User Preferences");
mUserPreferencesStage.setScene(scene);
mStages.add(mUserPreferencesStage);
mUserPreferences.getJavaFxPreferences().monitor(mUserPreferencesStage, STAGE_MONITOR_KEY_USER_PREFERENCES_EDITOR);
}

Expand Down Expand Up @@ -350,6 +381,7 @@ private Stage getChannelMapStage()
mChannelMapStage = new Stage();
mChannelMapStage.setTitle("sdrtrunk - Channel Map Editor");
mChannelMapStage.setScene(scene);
mStages.add(mChannelMapStage);
mUserPreferences.getJavaFxPreferences().monitor(mChannelMapStage, STAGE_MONITOR_KEY_CHANNEL_MAP_EDITOR);
}

Expand Down

0 comments on commit 6193e63

Please sign in to comment.