LWJGL3 + JavaFX crash on Linux

Started by piotrp, April 19, 2015, 18:34:00

Previous topic - Next topic

piotrp

Hi,

I have encountered a problem when using LWJGL3 together with JavaFX. Everything seems to work fine unless I open a new dialog.
I am attaching a test case to reproduce the issue. 
In most cases it ends up with the following error:

#  SIGSEGV (0xb) at pc=0x00007fdc59a3ec84, pid=4152, tid=140583549277952
#
# JRE version: Java(TM) SE Runtime Environment (8.0_45-b14) (build 1.8.0_45-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.45-b02 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libpthread.so.0+0x9c84]  pthread_mutex_lock+0x4


Any ideas how to fix/ work around the issue?

Thanks,
Piotr


Test case:

import static org.lwjgl.glfw.GLFW.glfwCreateWindow;
import static org.lwjgl.glfw.GLFW.glfwDefaultWindowHints;
import static org.lwjgl.glfw.GLFW.glfwInit;
import static org.lwjgl.opengl.GL11.GL_TRUE;
import static org.lwjgl.system.MemoryUtil.NULL;

import java.io.File;
import java.util.concurrent.CountDownLatch;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

public class JavaFXCrash extends Application {

    private final CountDownLatch latch = new CountDownLatch(1);
    private Stage stage;
    private long window;

    public static void main(String[] args) {
        launch(args);
    }

    public void startLWJGLThread() throws InterruptedException {
        Thread t = new Thread(() -> {
            setupNativeLibs();
            if (glfwInit() != GL_TRUE) {
                throw new IllegalStateException("Unable to initialize GLFW");
            }
            glfwDefaultWindowHints();
            window = glfwCreateWindow(500, 500, "LWJGL Window", NULL, NULL);
            latch.countDown();
        } );
        t.setDaemon(true);
        t.start();
        latch.await();
    }

    private void setupNativeLibs() {
        File natives = new File("lib/native");
        System.setProperty("org.lwjgl.librarypath", natives.getAbsolutePath());
    }

    @Override
    public void start(Stage stage) throws Exception {
        this.stage = stage;
        startLWJGLThread();
        BorderPane pane = new BorderPane();
        Scene scene = new Scene(pane, 850, 740);
        stage.setScene(scene);
        stage.show();
        Thread t = new Thread(() -> {
            try {
                Thread.sleep(1500);
                Platform.runLater(() -> {
                    openFileChooser();
                });
            } catch (Exception e) {
            }
        } );
        t.start();
    }

    protected File openFileChooser() {
        return new FileChooser().showOpenDialog(stage);
    }
}