javalwjglcoredump

Calling the "glClearColor()" function causes core dump


I'm new to LWJGL and OpenGL, and I've done some google searching and couldn't seem to find anything else related to this.

I made a basic test program to create a blank window. I can create the window and run the application fine, but if I try to change the clear color using glClearColor(), the application "crashes."

Here is the text printed in the console:

[error occurred during error reporting (printing problematic frame), id 0xe0000000]
# 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:
# /*****/*******/eclipse/java-neon/workspace/LWJGL Project/hs_err_pid10749.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.
#

This is the file that the error created (rather large): https://pastebin.com/9h0gsRmTlink

This is the code:

package me.smorce.project;

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.*;
import org.lwjgl.glfw.GLFWVidMode;
import me.smorce.project.input.Input;

public class Game
{
    public boolean running = false;
    private long window;
    public int windowWidth = 1280;
    public int windowHeight = windowWidth / 16 * 9;

    public void start()
    {
        running = true;
        init();
        while(running)
        {
            update();
            render();
            if(glfwWindowShouldClose(window)) running = false;
        }
    }

    private void init()
    {
        if(!glfwInit())
        {
            System.err.println("GLFW failed to initialize!");
            return;
        }
        glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
        window = glfwCreateWindow(windowWidth, windowHeight, "Game", NULL, NULL);
        if(window == NULL)
        {
            System.err.println("GLFW failed to create the window");
            return;
        }
        GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
        glfwSetWindowPos(window, (videoMode.width() - windowWidth) / 2, (videoMode.height() - windowHeight) / 2);
        glfwSetKeyCallback(window, new Input());
        glfwMakeContextCurrent(window);
        glEnable(GL_DEPTH_TEST);
        System.out.println("OpenGL: " + glGetString(GL_VERSION));
        glfwShowWindow(window);
        glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    }

    private void update()
    {
        glfwPollEvents();
        if(Input.keys[GLFW_KEY_SPACE])
        {
            System.out.println("SPACE BAR");
        }
    }

    private void render()
    {
        glfwSwapBuffers(window);
    }
}

Any pointers/tips would be helpful.


Solution

  • You are missing

    GL.createCapabilities();

    From the getting started:

    // This line (~the above) 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.
    

    Also, move glEnable(GL_DEPTH_TEST); after that line as well.

    You do not get a crash now on your machine, but you may with different conditions