Can't run the basic LWJGL class with Eclipse on Mac

Started by ThorenDragonGem, October 22, 2015, 10:36:55

Previous topic - Next topic

ThorenDragonGem

Hello guys, im having a big problem:
I wanted to dev with lwjgl 3, so i installed it, with the jar (LWJGL 3.0.0b build 52: the nightly), and with the natives. But when i ran it, i had this:

java.lang.NullPointerException
	at org.lwjgl.Sys.getVersionImpl(Sys.java:79)
	at org.lwjgl.Sys.getVersion(Sys.java:65)
	at org.lwjgl.Sys.<clinit>(Sys.java:35)
	at org.lwjgl.LWJGLUtil.initialize(LWJGLUtil.java:140)
	at org.lwjgl.system.MemoryUtil.<clinit>(MemoryUtil.java:55)
	at org.lwjgl.system.libffi.Closure.<clinit>(Closure.java:43)
	at com.thoren.test.HelloWorld.init(HelloWorld.java:39)
	at com.thoren.test.HelloWorld.run(HelloWorld.java:23)
	at com.thoren.test.HelloWorld.main(HelloWorld.java:110)
2015-10-22 12:19:07.888 java[4326:143670] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /SourceCache/Foundation/Foundation-1154/Misc.subproj/NSUndoManager.m:340
2015-10-22 12:19:07.890 java[4326:143670] +[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.
2015-10-22 12:19:07.891 java[4326:143670] (
	0   CoreFoundation                      0x00007fff8968303c __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x00007fff8bae776e objc_exception_throw + 43
	2   CoreFoundation                      0x00007fff89682e1a +[NSException raise:format:arguments:] + 106
	3   Foundation                          0x00007fff8a40f99b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
	4   Foundation                          0x00007fff8a39164f +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 156
	5   AppKit                              0x00007fff8d124b95 -[NSApplication run] + 756
	6   libglfw.dylib                       0x00000001231e985e initializeAppKit + 1342
	7   libglfw.dylib                       0x00000001231e8f72 _glfwPlatformCreateWindow + 34
	8   libglfw.dylib                       0x00000001231e58d0 glfwCreateWindow + 480
	9   ???                                 0x000000010e2134d4 0x0 + 4532024532
)
2015-10-22 12:19:07.891 java[4326:143670] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /SourceCache/Foundation/Foundation-1154/Misc.subproj/NSUndoManager.m:340
2015-10-22 12:19:07.893 java[4326:143670] An uncaught exception was raised
2015-10-22 12:19:07.893 java[4326:143670] +[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.
2015-10-22 12:19:07.893 java[4326:143670] (
	0   CoreFoundation                      0x00007fff8968303c __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x00007fff8bae776e objc_exception_throw + 43
	2   CoreFoundation                      0x00007fff89682e1a +[NSException raise:format:arguments:] + 106
	3   Foundation                          0x00007fff8a40f99b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
	4   Foundation                          0x00007fff8a39164f +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 156
	5   AppKit                              0x00007fff8d124c41 -[NSApplication run] + 928
	6   libglfw.dylib                       0x00000001231e985e initializeAppKit + 1342
	7   libglfw.dylib                       0x00000001231e8f72 _glfwPlatformCreateWindow + 34
	8   libglfw.dylib                       0x00000001231e58d0 glfwCreateWindow + 480
	9   ???                                 0x000000010e2134d4 0x0 + 4532024532
)
2015-10-22 12:19:07.902 java[4326:143670] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff8968303c __exceptionPreprocess + 172
	1   libobjc.A.dylib                     0x00007fff8bae776e objc_exception_throw + 43
	2   CoreFoundation                      0x00007fff89682e1a +[NSException raise:format:arguments:] + 106
	3   Foundation                          0x00007fff8a40f99b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
	4   Foundation                          0x00007fff8a39164f +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 156
	5   AppKit                              0x00007fff8d124c41 -[NSApplication run] + 928
	6   libglfw.dylib                       0x00000001231e985e initializeAppKit + 1342
	7   libglfw.dylib                       0x00000001231e8f72 _glfwPlatformCreateWindow + 34
	8   libglfw.dylib                       0x00000001231e58d0 glfwCreateWindow + 480
	9   ???                                 0x000000010e2134d4 0x0 + 4532024532
)
libc++abi.dylib: terminating with uncaught exception of type NSException


with this code (NB: this is the basic code found on lwjgl.org at Getting started):

package com.thoren.test;

import org.lwjgl.Sys;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
 
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.*;
 
public class HelloWorld {
 
    // We need to strongly reference callback instances.
    private GLFWErrorCallback errorCallback;
    private GLFWKeyCallback   keyCallback;
 
    // The window handle
    private long window;
 
    public void run() {
        System.out.println("Hello LWJGL " + Sys.getVersion() + "!");
 
        try {
            init();
            loop();
 
            // Release window and window callbacks
            glfwDestroyWindow(window);
            keyCallback.release();
        } finally {
            // Terminate GLFW and release the GLFWErrorCallback
            glfwTerminate();
            errorCallback.release();
        }
    }
 
    private void init() {
        // Setup an error callback. The default implementation
        // will print the error message in System.err.
        glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err));
 
        // Initialize GLFW. Most GLFW functions will not work before doing this.
        if ( glfwInit() != GL11.GL_TRUE )
            throw new IllegalStateException("Unable to initialize GLFW");
 
        // Configure our window
        glfwDefaultWindowHints(); // optional, the current window hints are already the default
        glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation
        glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable
 
        int WIDTH = 300;
        int HEIGHT = 300;
 
        // Create the window
        window = glfwCreateWindow(WIDTH, HEIGHT, "Hello World!", NULL, NULL);
        if ( window == NULL )
            throw new RuntimeException("Failed to create the GLFW window");
 
        // Setup a key callback. It will be called every time a key is pressed, repeated or released.
        glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {
            @Override
            public void invoke(long window, int key, int scancode, int action, int mods) {
                if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE )
                    glfwSetWindowShouldClose(window, GL_TRUE); // We will detect this in our rendering loop
            }
        });
 
        // Get the resolution of the primary monitor
        GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
        // Center our window
        glfwSetWindowPos(
            window,
            (vidmode.getWidth() - WIDTH) / 2,
            (vidmode.getHeight() - HEIGHT) / 2
        );
 
        // Make the OpenGL context current
        glfwMakeContextCurrent(window);
        // Enable v-sync
        glfwSwapInterval(1);
 
        // Make the window visible
        glfwShowWindow(window);
    }
 
    private void loop() {
        // This line is critical for LWJGL's interoperation with GLFW's
        // OpenGL context, or any context that is managed externally.
        // LWJGL detects the context that is current in the current thread,
        // creates the GLCapabilities instance and makes the OpenGL
        // bindings available for use.
        GL.createCapabilities();
 
        // Set the clear color
        glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
 
        // Run the rendering loop until the user has attempted to close
        // the window or has pressed the ESCAPE key.
        while ( glfwWindowShouldClose(window) == GL_FALSE ) {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
 
            glfwSwapBuffers(window); // swap the color buffers
 
            // Poll for window events. The key callback above will only be
            // invoked during this call.
            glfwPollEvents();
        }
    }
 
    public static void main(String[] args) {
        new HelloWorld().run();
    }
 
}


I searched solutions on Google, but i didn't found a working answer. I tried also to make a "Fat jar" with jarSplice, but it didnt work.

Hope you found an answer to this problem.
Thanks in advance.

Cornix

Although I can not help you directly a quick google search has led me to this:
https://github.com/AlexCharlton/cl-glfw3/issues/10

The fine people in the linked thread seem to think an error like this happens when GLFW is not initialized on the main thread.

spasi

Short answer: Launch the JVM with the -XstartOnFirstThread argument.

For more details, please read this issue.