gpt4 book ai didi

c++ - OpenGL glfwGetVideoMode 导致段错误

转载 作者:行者123 更新时间:2023-12-05 02:26:51 24 4
gpt4 key购买 nike

我有一个简单的程序,我想在其中检查 GLFW 窗口的格式,但是 glfwGetVideoMode 导致段错误。

这是我的代码:

        if (!glfwInit()) {
VI_ERROR("Couldn't init GLFW\n");
exit(0);
}

glfwWindowHint(GLFW_SAMPLES, 6);


window = glfwCreateWindow(gl_width, gl_height, "GLFW Context", NULL, NULL);

if (!window) {
VI_ERROR("Couldn't open window\n");
exit(0);
}

glfwMakeContextCurrent(window);

gladLoadGL();

GLFWmonitor* wmonitor = glfwGetWindowMonitor(window);

glfwGetVideoMode(wmonitor);

Valgrind 是这样说的:

==56501== Invalid read of size 8
==56501== at 0xDF31CB: _glfwPlatformGetVideoMode (in /home/turgut/Desktop/CppProjects/videoo-render/bin/Renderer)
==56501== by 0xDEDE51: glfwGetVideoMode (in /home/turgut/Desktop/CppProjects/videoo-render/bin/Renderer)
==56501== by 0x21F8F6: OpenGL::OpenGLRenderer::OpenGLRenderer(int, int, int, int) (OpenGLRenderer.cpp:27)
==56501== by 0x21BC7A: Application::Run() (Application.cpp:77)
==56501== by 0x21AB6E: main (main.cpp:18)
==56501== Address 0x108 is not stack'd, malloc'd or (recently) free'd
==56501==
==56501==
==56501== Process terminating with default action of signal 11 (SIGSEGV)
==56501== Access not within mapped region at address 0x108
==56501== at 0xDF31CB: _glfwPlatformGetVideoMode (in /home/turgut/Desktop/CppProjects/videoo-render/bin/Renderer)
==56501== by 0xDEDE51: glfwGetVideoMode (in /home/turgut/Desktop/CppProjects/videoo-render/bin/Renderer)
==56501== by 0x21F8F6: OpenGL::OpenGLRenderer::OpenGLRenderer(int, int, int, int) (OpenGLRenderer.cpp:27)
==56501== by 0x21BC7A: Application::Run() (Application.cpp:77)
==56501== by 0x21AB6E: main (main.cpp:18)
==56501== If you believe this happened as a result of a stack
==56501== overflow in your program's main thread (unlikely but
==56501== possible), you can try to increase the size of the
==56501== main thread stack using the --main-stacksize= flag.
==56501== The main thread stack size used in this run was 8388608.

我做错了什么?就这么简单。

最佳答案

主要问题是 glfwGetWindowMonitor 返回 null,因此 glfwGetVideoMode 导致读取 nullptr。

在 GLFW 中,只有全屏窗口与监视器关联。由于您将 NULL 作为第四个参数传递给 glCreateWindow 并且从不调用 glfwSetWindowMonitor,因此当前窗口处于窗口模式并且不会有关联的监视器。

关于c++ - OpenGL glfwGetVideoMode 导致段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73598632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com