我有一个简单的程序,我想检查我的GLFW窗口的格式,但glfwGetVideoMode
导致段错误。
以下是我的代码:
if (!glfwInit()) {
VI_ERROR("Couldn't init GLFWn");
exit(0);
}
glfwWindowHint(GLFW_SAMPLES, 6);
window = glfwCreateWindow(gl_width, gl_height, "GLFW Context", NULL, NULL);
if (!window) {
VI_ERROR("Couldn't open windown");
exit(0);
}
glfwMakeContextCurrent(window);
gladLoadGL();
GLFWmonitor* wmonitor = glfwGetWindowMonitor(window);
glfwGetVideoMode(wmonitor);
瓦尔格林德说过:
==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.
我能做错什么呢?事情就是这么简单。
1条答案
按热度按时间zwghvu4y1#
主要问题是
glfwGetWindowMonitor
返回NULL,因此glfwGetVideoMode
导致从nullptr读取。在GLFW中,只有全屏窗口与显示器相关联。由于您将
NULL
作为第四个参数传递给glCreateWindow
,并且从不调用glfwSetWindowMonitor
,因此当前窗口处于窗口模式,并且不会有关联的监视器。