GLFW may only be used on the main thread and that thread must be the first thread in the process

Hi,

I’m beginning (and start learning) with jMonkeyEngine and trying to run the sample game (cf. jMonkeyEngine | Quick Start)

After experiencing a first issue here ((SOLVED) LWJGL3: ERROR: Context class is missing!)

I now have this issue:

GRAVE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.ExceptionInInitializerError
	at org.lwjgl.glfw.GLFW.glfwInit(GLFW.java:1046)
	at com.jme3.system.lwjgl.LwjglWindow.createContext(LwjglWindow.java:203)
	at com.jme3.system.lwjgl.LwjglWindow.initInThread(LwjglWindow.java:529)
	at com.jme3.system.lwjgl.LwjglWindow.run(LwjglWindow.java:662)
	at com.jme3.system.lwjgl.LwjglWindow.create(LwjglWindow.java:493)
	at com.jme3.app.LegacyApplication.start(LegacyApplication.java:490)
	at com.jme3.app.LegacyApplication.start(LegacyApplication.java:442)
	at com.jme3.app.SimpleApplication.start(SimpleApplication.java:126)
	at com.elua.Main.main(Main.java:20)
Caused by: java.lang.IllegalStateException: GLFW may only be used on the main thread and that thread must be the first thread in the process. Please run the JVM with -XstartOnFirstThread. This check may be disabled with Configuration.GLFW_CHECK_THREAD0.
	at org.lwjgl.glfw.EventLoop.<clinit>(EventLoop.java:30)
	... 9 more

So, I tried to add the JVM argument -XstartOnFirstThread, but when I do this, the application does not start.
(I’m on MacOS 12.0.1)

This is my maven dependencies configuration:

<dependencies>
  	<dependency>
  		<groupId>org.jmonkeyengine</groupId>
  		<artifactId>jme3-core</artifactId>
  		<version>3.5.2-stable</version>
  	</dependency>
  	<dependency>
  		<groupId>org.jmonkeyengine</groupId>
  		<artifactId>jme3-desktop</artifactId>
  		<version>3.5.2-stable</version>
  	</dependency>
  	<dependency>
  		<groupId>org.jmonkeyengine</groupId>
  		<artifactId>jme3-lwjgl3</artifactId>
  		<version>3.5.2-stable</version>
  	</dependency>
  </dependencies>

And the code i’m trying to run:

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
 
public class Main extends SimpleApplication {
 
    public static void main(String[] args) {
 
        Main app = new Main();
 
        AppSettings settings = new AppSettings(true);
        settings.setTitle("My Awesome Game");
        app.setSettings(settings);
 
        app.start();
 
    }
 
    @Override
    public void simpleInitApp() {
 
        Box b = new Box(1, 1, 1);
        Geometry geom = new Geometry("Box", b);
 
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);
        geom.setMaterial(mat);
 
        rootNode.attachChild(geom);
 
    }
 
    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
    }
 
}

Also tried something else, by adding “app.initialize();” before “app.start();”. But got this:

juin 25, 2022 6:18:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.MeshLoader
juin 25, 2022 6:18:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.SkeletonLoader
juin 25, 2022 6:18:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.MaterialLoader
juin 25, 2022 6:18:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.SceneLoader
juin 25, 2022 6:18:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.fbx.FbxLoader
juin 25, 2022 6:18:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.GltfLoader
juin 25, 2022 6:18:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.BinLoader
juin 25, 2022 6:18:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.GlbLoader
juin 25, 2022 6:18:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.audio.plugins.OGGLoader
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.jme3.system.JmeContext.getSettings()" because "this.context" is null
	at com.jme3.app.LegacyApplication.initDisplay(LegacyApplication.java:278)
	at com.jme3.app.LegacyApplication.initialize(LegacyApplication.java:637)
	at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:198)
	at com.elua.Main.main(Main.java:20)

Is there an issue with MacOS or anything else ?
Thanks for your help :slight_smile:

1 Like

Don’t do that. It will totally break everything. You should never ever ever ever ever ever ever ever ever ever ever ever call app.initialize() yourself. It absolutely must be called by the JME infrastructure as part of startup.

As to your actual topic, this comes up on the forum quite often. You may try searching for glfw, thread, etc.

Does this mean you are on MacOS? It’s definitely harder to get things working on Mac. It’s a very OpenGL-hostile environment these days.

…but folks have done it.

1 Like

By setting -XstartOnFirstThread on Program arguments instead of VM arguments. It seems to be good.

But, I got this issue now:

juin 25, 2022 8:39:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.MeshLoader
juin 25, 2022 8:39:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.SkeletonLoader
juin 25, 2022 8:39:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.MaterialLoader
juin 25, 2022 8:39:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.SceneLoader
juin 25, 2022 8:39:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.fbx.FbxLoader
juin 25, 2022 8:39:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.GltfLoader
juin 25, 2022 8:39:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.BinLoader
juin 25, 2022 8:39:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.GlbLoader
juin 25, 2022 8:39:08 PM com.jme3.asset.AssetConfig loadText
AVERTISSEMENT: Cannot find loader com.jme3.audio.plugins.OGGLoader
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.jme3.system.JmeContext.getSettings()" because "this.context" is null
	at com.jme3.app.LegacyApplication.initDisplay(LegacyApplication.java:278)
	at com.jme3.app.LegacyApplication.initialize(LegacyApplication.java:637)
	at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:198)
	at com.elua.Main.main(Main.java:20)

Looking into it, I will reply here when I found a solution.

Well, you are still calling app.initialize from main like I said not to.

See above.

Then if you miss the above, read it again.

Do NOT, as in don’t do it, never do it, banish it from your mind… call app.initialize() yourself.

You will have better luck just deleting your code and staring at a blank wall.

II was sure I deleted it and I actually left it. I’m stupid, sorry :laughing:

Starting to wonder if perhaps initialize() should be marked as @deprecated with a detailed custom message?

It literally won’t matter.

But it is not deprecated. It is alive and well. Deprecating a method means that no one should use it. Maybe just improve the javadoc?

1 Like