【发布时间】:2020-05-10 22:56:31
【问题描述】:
我正在尝试使用 glfw 开发一个程序,其中窗口在主循环中关闭。但是,我收到了这个奇怪的运行时错误:
X Error of failed request: GLXBadDrawable
Major opcode of failed request: 152 (GLX)
Minor opcode of failed request: 11 (X_GLXSwapBuffers)
Serial number of failed request: 158
Current serial number in output stream: 158
这是我要运行的代码
#include <GL/glfw3.h>
int main()
{
GLFWwindow* window;
if(!glfwInit())
return -1;
window = glfwCreateWindow(400, 400, "window", nullptr, nullptr);
if(!window)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
while(!glfwWindowShouldClose(window))
{
glfwDestroyWindow(window);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
有没有办法从主循环内部破坏窗口?
【问题讨论】:
-
当之前的测试
glfwWindowShouldClose告诉你不要关闭它时,你为什么要打电话给glfwDestroyWindow? -
@Ripi2 好点,这是否意味着我必须手动使用
while(true)循环并在窗口关闭时中断?如果是这样,我如何创建一个事件侦听器以在窗口关闭时提醒我? -
只需将
glfwDestroyWindow移动到glfwTerminate之前 -
为什么要在主循环中销毁窗口?为什么要在创建窗口后立即销毁窗口?
-
@MaximV 为什么要在主循环中调用
glfwDestroyWindow。我不明白你想要达到什么目的。这根本没有意义。你为什么不直接打破循环?拨打glfwDestroyWindow后,您无法拨打glfwSwapBuffers或glfwPollEvents。因此答案是否定的。你不能打电话给glfwDestroyWindow,然后glfwSwapBuffers