I'm trying to open multiple frame and shutdown them all.This is a test class to do that.
But when I call the method "System.exit()",after closing the last frame, there's an error message occurred in console.
- Code: Select all
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x1a91b9c7, pid=8280, tid=8668
#
# JRE version: Java(TM) SE Runtime Environment (8.0_74-b02) (build 1.8.0_74-b02)
# Java VM: Java HotSpot(TM) Client VM (25.74-b02 mixed mode windows-x86 )
# Problematic frame:
# C [jcef.dll+0x1b9c7]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
My code is:
- Code: Select all
public class MultiMainFrame extends JFrame {
private static final long serialVersionUID = -5570653778104813836L;
private final JTextField address_;
static private CefApp cefApp_;
static private CefClient client_;
private final CefBrowser browser_;
private final Component browerUI_;
private MultiMainFrame(String startURL, boolean useOSR, boolean isTransparent) {
if (cefApp_ == null) {
CefApp.addAppHandler(new CefAppHandlerAdapter(null) {
@Override
public void stateHasChanged(org.cef.CefApp.CefAppState state) {
System.out.println(state);
// Shutdown the app if the native CEF part is terminated
if (state == CefAppState.TERMINATED){
System.out.println("ttt");
// System.exit(0);
}
}
});
CefSettings settings = new CefSettings();
settings.windowless_rendering_enabled = useOSR;
cefApp_ = CefApp.getInstance(settings);
client_ = cefApp_.createClient();
}
browser_ = client_.createBrowser(startURL, useOSR, isTransparent);
browerUI_ = browser_.getUIComponent();
address_ = new JTextField(startURL, 100);
address_.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
browser_.loadURL(address_.getText());
}
});
getContentPane().add(address_, BorderLayout.NORTH);
getContentPane().add(browerUI_, BorderLayout.CENTER);
pack();
setSize(800, 600);
setVisible(true);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
CefApp cefApp = CefApp.getInstance();
synchronized (MultiMainFrame.class) {
int activeFrameCount = getActiveFrameCount();
if (activeFrameCount <= 1 && !cefDisposed) {
cefApp.dispose();
cefDisposed = true;
}
}
if (isDisplayable()) {
dispose();
}
// CefApp.getInstance().dispose();
// dispose();
}
});
}
public static int getActiveFrameCount() {
Frame[] frames = Frame.getFrames();
int leftFrame = 0;
for (int i = 0; i < frames.length; i++) {
if (frames[i].isDisplayable()) {
leftFrame++;
}
}
return leftFrame;
}
private static boolean cefDisposed = false;
public static void main(String[] args) throws InterruptedException {
new MultiMainFrame("http://www.google.com", OS.isLinux(), false);
Thread.sleep(1000);
new MultiMainFrame("http://www.google.com", OS.isLinux(), false);
Thread.sleep(10000);
System.exit(0);
}
}
How to deal with it? Although it doesn't affect the program.
It didn't make a influence on the project ,but