首页 > 解决方案 > glfwSwapBuffers(窗口); 失败并抛出异常

问题描述

我在这里从官方 GLFW 文档中复制了一些代码:https ://www.glfw.org/documentation.html但它一直在它所说的地方引发异常glfwSwapBuffers();

在 Main.exe 中的 0x0000000000000000 处引发异常:0xC0000005:访问冲突执行位置 0x0000000000000000

#include<iostream>
#include<glad/glad.h>
#include<GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    
    glfwInit();

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (window == NULL)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

标签: c++openglglfw

解决方案


推荐阅读