【问题标题】:Calling the "glClearColor()" function causes core dump调用“glClearColor()”函数会导致核心转储
【发布时间】:2017-11-01 09:58:36
【问题描述】:

我是 LWJGL 和 OpenGL 的新手,我进行了一些谷歌搜索,但似乎找不到与此相关的任何其他内容。

我做了一个基本的测试程序来创建一个空白窗口。我可以创建窗口并正常运行应用程序,但如果我尝试使用 glClearColor() 更改清除颜色,应用程序“崩溃”。

这是控制台中打印的文本:

[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.
#

这是错误创建的文件(相当大): https://pastebin.com/9h0gsRmTlink

这是代码:

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);
    }
}

任何指针/提示都会有所帮助。提前致谢。

【问题讨论】:

  • 如果最好直接在此处发布您的代码,而不是链接,尤其是如果它很短(错误输出可能有点大,但您至少可以发布通常包含最重要的第一部分反正信息)。这样做会更容易阅读和理解您的问题,因此人们会更愿意提供帮助 - 最后但并非最不重要的一点是:链接可能会随着时间的推移而中断。
  • @Thomas 谢谢你,我更新了。

标签: java lwjgl core dump


【解决方案1】:

你不见了

GL.createCapabilities();

来自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.

另外,将glEnable(GL_DEPTH_TEST); 也移到该行之后。

您的机器现在不会崩溃,但您可能会遇到不同的情况

【讨论】:

  • 嗯,有道理。非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多