OpenGl异常错误VisualStudio:在fps-opengl.exe中的0x 0000000000000000处抛出异常:0xC0000005:访问冲突执行位置[已关闭]

4xy9mtcn  于 2023-05-17  发布在  其他
关注(0)|答案(1)|浏览(204)

**关闭。**此题需要debugging details。目前不接受答复。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答这个问题。
7天前关闭
Improve this question
每当我尝试调整窗口大小时,都会遇到这个问题:Exception thrown at 0x0000000000000000 in fps-opengl.exe: 0xC0000005: Access violation executing location 0x0000000000000000.
这是我目前为止的代码:

#include "engine.h"
#include "Source.h"

//void framebuffer_size_callback(GLFWwindow* window, int width, int height);
int main() {

    //engine engine();
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window = glfwCreateWindow(800, 600, "wonder window", NULL, NULL);

    if (window == nullptr) {
        std::cout << "error init window" << std::endl;
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);
    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
    while (!glfwWindowShouldClose(window)) {
        // implement calculation of elapsed time here pass to onuserinput
        //engine.onuserinput();
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwTerminate();
    return 0;
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
    glViewport(0, 0, width, height);
}

engine.h是空的,除了glfw includes和glad。Visual studio在glviewport行后发现错误。

qco9c6ql

qco9c6ql1#

在调用任何其他OpenGL方法之前,需要初始化glad库。glad github repo上的说明建议在打开窗口并绑定上下文后必须调用以下代码:

int version = gladLoadGL(glfwGetProcAddress);
if (version == 0) {
    //Initialization failed
}

相关问题