Skip to content

Commit

Permalink
ui: set DO_NOTHING_ON_CLOSE close op prior to disposing
Browse files Browse the repository at this point in the history
Disposed frames are still reachable via Window.getWindows() until gcd, and can
receive and process events. We don't want the splash screen to close the app if
it receives a window close event after being disposed.
  • Loading branch information
Adam- committed Jan 2, 2022
1 parent 31dc32c commit 0da5047
Showing 1 changed file with 7 additions and 2 deletions.
Expand Up @@ -30,7 +30,6 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import javax.annotation.Nullable;
import javax.swing.ImageIcon;
Expand Down Expand Up @@ -66,7 +65,7 @@ public class SplashScreen extends JFrame implements ActionListener
private volatile String subActionText = "";
private volatile String progressText = null;

private SplashScreen() throws IOException
private SplashScreen()
{
BufferedImage logo = ImageUtil.loadImageResource(SplashScreen.class, "runelite_transparent.png");

Expand Down Expand Up @@ -204,6 +203,12 @@ public static void stop()
}

INSTANCE.timer.stop();
// The CLOSE_ALL_WINDOWS quit strategy on MacOS dispatches WINDOW_CLOSING events to each frame
// from Window.getWindows. However, getWindows uses weak refs and relies on gc to remove windows
// from its list, causing events to get dispatched to disposed frames. The frames handle the events
// regardless of being disposed and will run the configured close operation. Set the close operation
// to DO_NOTHING_ON_CLOSE prior to disposing to prevent this.
INSTANCE.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
INSTANCE.dispose();
INSTANCE = null;
});
Expand Down

0 comments on commit 0da5047

Please sign in to comment.