从IntelliJ运行JavaFX和Swing时的Segfault

时间:2016-03-29 12:56:16

标签: java swing intellij-idea javafx openjdk

从IntelliJ 2016.1社区版运行以下缩小示例时,我总是遇到分段错误:

import javax.swing.*;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

public class Repro extends Application {

    public static void main(String[] args) {
        JFrame swingFrame = new JFrame();
        swingFrame.setTitle("Repro start");
        swingFrame.setSize(200, 350);
        swingFrame.setVisible(true);

        Application.launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        Pane root = new Pane();
        root.setMinHeight(200);
        root.setMinWidth(350);
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }
}

环境如下:

  • Ubuntu 15.10
  • openjdk-8(1.8.0_u66 build 17)
  • openjfx-8(8u60-b27-4)
  • IntelliJ 2016.1社区版(build#IC-145.258)

javac运行到java中,无法重现此问题 通过oraclejdk(1.8.0_u77-b03)

运行时,问题也没有显示出来

作为参考,该程序的“输出”如下:

Prism-ES2 Error : GL_VERSION (major.minor) = 1.4
Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" Exception in thread "JavaFX Application Thread" #
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (safepoint.cpp:712), pid=16937, tid=140197878814464
#  fatal error: Illegal threadstate encountered: 6
#
# JRE version: OpenJDK Runtime Environment (8.0_66-b17) (build 1.8.0_66-internal-b17)
# Java VM: OpenJDK 64-Bit Server VM (25.66-b17 mixed mode linux-amd64 compressed oops)
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/vogel612/.../hs_err_pid16937.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#

Process finished with exit code 134

运行ulimit -c unlimited并重新启动IntelliJ

后问题仍然存在

根据要求,this gist.

提供了此类执行的错误日志

如何解决此问题?

1 个答案:

答案 0 :(得分:1)

错误可以在IntelliJ之外复制,如下所示。

public class Main {
    public static void main(String[] args) throws Exception {
        new Repro().main(new String[0]);
    }
}

使用

在Ubuntu 15.10上运行java -cp . Main
  

openjdk version“1.8.0_66-internal”
  OpenJDK运行时环境(版本1.8.0_66-internal-b17)
  OpenJDK 64位服务器VM(版本25.66-b17,混合模式)

会产生同样的致命错误。而java -cp . Repo运行不会失败。

使用

在CentOS 7上运行java -cp . Main
  

openjdk version“1.8.0_77”
  OpenJDK运行时环境(版本1.8.0_77-b03)
  OpenJDK 64位服务器VM(内置25.77-b03,混合模式)

打开Swing JFrame和JavaFX窗格。

似乎这个问题与特定的OpenJDK版本以及调用类Repo的方式有关。

编辑如果您无法切换到其他Java版本,则可能存在“解决方法”。 (基于此post

修改您的Repro.java,如下所示,OpenJDK Runtime Environment (build 1.8.0_66-internal-b17)

不会失败
public static void main(String[] args) throws Exception {
    new JFXPanel(); // the "workaround" to initialize the toolkit
    JFrame swingFrame = new JFrame();
    ...