oracle/graal

-XstartOnFirstThread support

Closed this issue · 3 comments

mryvz commented

I ve created a basic lwjgl3 application which requires to run -XstartOnFirstThread vm parameter on Mac. But i cannot pass parameter to substratevm and getting error below.

Caused by: java.lang.IllegalStateException: GLFW windows may only be created on the main thread and that thread must be the first thread in the process. Please run the JVM with -XstartOnFirstThread. For offscreen rendering, make sure another window toolkit (e.g. AWT or JavaFX) is initialized before GLFW.

olpaw commented
> native-image --help

GraalVM native-image building tool

This tool can be used to generate an image that contains ahead-of-time compiled Java code.

Usage: native-image [options] class [imagename]
           (to build an image for a class)
   or  native-image [options] -jar jarfile [imagename]
           (to build an image for a jar file)
where options include:
    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
    --class-path <class search path of directories and zip/jar files>
                          A : separated list of directories, JAR archives,
                          and ZIP archives to search for class files.
    -D<name>=<value>      set a system property
==> -J<flag>              pass <flag> directly to the JVM running the image generator  <==

Please try with -J-XstartOnFirstThread

mryvz commented

Already i ve tried, also tried to run native app with -XstartOnFirstThread but no difference. Im using build command below;
~/Workspace/Library/java/graalvm-ce-java11-19.3.0/Contents/Home/bin/native-image -cp <lots of deps > -J-XstartOnFirstThread -ea --no-server -H:+AllowVMInspection -H:Class=test.graalvm.graaltest.Main

As workaround, i can start glfw window if i initialize javafx toolkit before glfwInit().

....
com.sun.javafx.application.PlatformImpl.startup(() -> {
          HelloWorld.main(args);
});
....

It seems you found another solution for your problem. Please reopen is this issue is still relevant.