0
\$\begingroup\$

Whenever I run my code to make a fullscreen GLFW window, it crashes.

Here is the code:

package ext.tpz.test;

import static org.lwjgl.glfw.GLFW.*;

public class Main {

    public Main() {
    }

    public static void main(String[] args) {
        if (glfwInit() == false) {
            System.out.println("GLFW failed to init.");
            System.exit(1);
        }
        long fullscreen = 0;
        if(args.length >= 1) {
            if (args[0].equals("-fullscreen")) {
                fullscreen = 1;
            }
        }
        long win = glfwCreateWindow(640,480, "Test", fullscreen, 0);


        glfwShowWindow(win);
        while(glfwWindowShouldClose(win) == false ) {
            glfwPollEvents();
        }

        glfwTerminate();
    }
}

Here is the crash report:

A fatal error has been detected by the Java Runtime Environment:

SIGSEGV (0xb) at pc=0x000000012dd11841, pid=13565, tid=1811

JRE version: Java(TM) SE Runtime Environment (8.0_65-b17) (build 1.8.0_65-b17) Java VM: Java HotSpot(TM) 64-Bit Server VM (25.65-b01 mixed mode bsd-amd64 compressed oops) Problematic frame: C [libglfw.dylib+0x9841]

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: /Users/a677c774/IdeaProjects/LWJGL 3 Tests/hs_err_pid13565.log

If you would like to submit a bug report, please visit: http://bugreport.java.com/bugreport/crash.jsp The crash happened outside the Java Virtual Machine in native code. See problematic frame for where to report the bug.

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

\$\endgroup\$
0
1
\$\begingroup\$

The problem was that you set the fullscreen variable to 1, instead this variable should be set to a monitor value.

To retrieve the default monitor's value you can call glfw's method glfwGetPrimaryMonitor().

This should solve the main issue, besides of that I have also added the context creation, window update and window clearing function calls.

You can find a documentation on how to use glfw at
http://www.glfw.org/docs/latest/

import org.lwjgl.opengl.GL;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.NULL;

public static void main(String[] args) {
    if (!glfwInit()) {
        System.out.println("Failed to initialize GLFW.");
        System.exit(1);
    }

    long fullscreen = NULL;
    if(args.length >= 1) {
        if (args[0].equals("-fullscreen")) {
            fullscreen = glfwGetPrimaryMonitor();
        }
    }

    long window = glfwCreateWindow(640, 480, "Test", fullscreen, NULL);
    if (window == NULL) {
        System.out.println("Failed to create the window.");
        glfwTerminate();
        System.exit(1);
    }

    glfwMakeContextCurrent(window);
    GL.createCapabilities(); 

    while(!glfwWindowShouldClose(window)) {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwTerminate();
}
\$\endgroup\$
8
  • \$\begingroup\$ Please describe what changed from what the user posted, how you fixed it and how you discovered the issue. This will make a much better answer. \$\endgroup\$
    – Vaillancourt
    Aug 17 '16 at 11:43
  • \$\begingroup\$ Alexandre, I did not discover this, it is just my default way of working, therefore I only gave a summary about the changes and why it should be changed. Thank you for the advice on commenting though. \$\endgroup\$
    – Tripl3Fac3
    Aug 17 '16 at 12:01
  • \$\begingroup\$ Ah, then perhaps you should change "This should solve your problem. " by something like "I'm not sure exactly how to fix your specific issue, but here is the way I do what you're attempting with lwjgl and glfw. " That would be a bit more exact :) \$\endgroup\$
    – Vaillancourt
    Aug 17 '16 at 12:04
  • \$\begingroup\$ Not really, the problem was that he set the value of fullscreen to 1 but it is supposed to be assigned to a monitor value, which preferably is the default monitor, the way to get the default monitor value is glfwGetPrimaryMonitor();. Therefore the question is solved. I do know how to fix it but this is not a discovery, this is just how I found it in the glfw documentation when I started using glfw. \$\endgroup\$
    – Tripl3Fac3
    Aug 17 '16 at 12:13
  • \$\begingroup\$ " the problem was that he set the value of fullscreen to 1 but it is supposed to be assigned to a monitor value, which preferably is the default monitor, the way to get the default monitor value is glfwGetPrimaryMonit‌​or(); [...] I found it in the glfw documentation" that's just the kind explanation that is expected to be seen before the chunk of code in the answer :) \$\endgroup\$
    – Vaillancourt
    Aug 17 '16 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.