提问人:Rex 提问时间:8/22/2017 最后编辑:Rabbid76Rex 更新时间:8/22/2017 访问量:3478
glfwWindowShouldClose 错误 [已关闭]
glfwWindowShouldClose error [closed]
问:
闭。此问题不符合 Stack Overflow 准则。它目前不接受答案。
6年前关闭。
- 这个问题是由一个错别字或一个无法再重现的问题引起的。虽然类似的问题可能在这里成为主题,但这个问题的解决方式不太可能帮助未来的读者。
- 编辑问题以包括所需的行为、特定问题或错误以及重现问题所需的最短代码。这将有助于其他人回答这个问题。
我目前正在使用 opengl 和 glfw 制作一个小型 c++ 引擎,在尝试调用该函数时遇到一个奇怪的错误,这是我的代码:glfwWindowShouldClose(window)
#include "Engine\Window.h"
#include <iostream>
using namespace std;
int main()
{
GLFWwindow* window = 0;
Window::InitGLFW();
Window::CreateWindow(window,640,480,"1");
while (true)
{
if (glfwWindowShouldClose(window))//here is the error
{
Window::DestroyWindow(window);
Window::EndGLFW();
return 0;
}
}
system("pause");
return 0;
}
Window.h 文件:
#ifndef ENGINE_WINDOW
#define ENGINE_WINDOW
#include <iostream>
#include <vector>
#include "GL\glew.h"
#include "GLFW\glfw3.h"
using namespace std;
class Window
{
public:
static bool InitGLFW();
static void EndGLFW();
static bool CreateWindow(GLFWwindow* Window, int Width, int Height, char* Title);
static void DestroyWindow(GLFWwindow* Window);
private:
static void error_callback(int error, const char* description);
};
#endif
现在 Window.cpp 文件:
#include "Window.h"
void Window::error_callback(int error, const char* description)
{
cout << "Error: %s\n" << description;
}
bool Window::CreateWindow(GLFWwindow* Window, int Width, int Height,char* Title)
{
Window = glfwCreateWindow(Width, Height, Title, NULL, NULL);
if (!Window)
{
cout << "Window or OpenGL context creation failed";
return 1;
}
glfwMakeContextCurrent(Window);
return 0;
}
bool Window::InitGLFW()
{
glfwSetErrorCallback(error_callback);
if (!glfwInit())
{
cout << "glfw Initialization failed";
return 1;
}
}
void Window::DestroyWindow(GLFWwindow* Window)
{
glfwDestroyWindow(Window);
}
void Window::EndGLFW()
{
glfwTerminate();
}
所以正如你所看到的,程序在运行时给了我一个错误,而不是在我编译时,错误是:
Unhandled exception to 0x56B34B9F (glfw3.dll) in Engine.exe: 0xC0000005: Access violation when reading location 0x00000014.
我假设没有创建查看的变量?glfwWindowShouldClose
如果您需要知道我在 Windows 10 上运行并且我使用 Visual Studio 2015
答:
2赞
derhass
8/22/2017
#1
if (glfwWindowShouldClose(window))//here is the error
那是因为 NULL 指针。window
您可以在此处初始化它:
GLFWwindow* window = 0;
并且永远不会再改变它的价值。
此功能
bool Window::CreateWindow(GLFWwindow* Window, int Width, int Height,char* Title) { Window = glfwCreateWindow(Width, Height, Title, NULL, NULL); [...] }
只是更新它是变量的本地副本,并在函数离开时泄漏指针。Window
评论