glfwWindowShouldClose error
glfwWindowShouldClose error
本文关键字:error glfwWindowShouldClose 更新时间:2023-10-16
我目前正在使用 opengl 和 glfw 制作一个小型 c++ 引擎,在尝试调用glfwWindowShouldClose(window)
函数时出现一个奇怪的错误 这是我的代码:
#include "EngineWindow.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;
}
窗口.h 文件 :
#ifndef ENGINE_WINDOW
#define ENGINE_WINDOW
#include <iostream>
#include <vector>
#include "GLglew.h"
#include "GLFWglfw3.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
现在窗口.cpp文件:
#include "Window.h"
void Window::error_callback(int error, const char* description)
{
cout << "Error: %sn" << 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
if (glfwWindowShouldClose(window))//here is the error
这是因为window
是一个空指针。
您可以在此处初始化它:
GLFWwindow* window = 0;
,再也不会改变它的价值。
此函数
bool Window::CreateWindow(GLFWwindow* Window, int Width, int Height,char* Title) { Window = glfwCreateWindow(Width, Height, Title, NULL, NULL); [...] }
只是更新它是Window
变量的本地副本,并在函数离开时泄漏指针。
相关文章:
- "error: no matching function for call to"构造函数错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- C++错误:"error: int aaa::bbb is protected within this context"
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- C++ "error: invalid use of void expression"
- struct.error:解压缩 C++ 结构时,解包需要 288 字节的缓冲区
- 如何修复"error: ‘_1’ was not declared in this scope"?
- 从不同目录执行时"symbol lookup error:",否则从构建目录执行时按预期工作
- 对象声明中的模板"error: expected expression"
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- OpenCV 3.4.1 error readNetFromTensorflow 无法在 cv::d nn::ReadProtoFromBinaryFile 中打开 .pb
- 已解决 - C++ 的崇高文本中的"fatal error: opencv: no such file or directory"
- 为什么我会"error: expected expression"?
- CMake Error at modules/videoio/cmake/detect_ffmpeg.cmake:16
- 如果两个静态库使用相同的另一个静态库,如何避免"LNK2005 Already Defined error"?
- 在 Objective-C++ -> EXC_BAD_ACCESS Error 中使用"new"关键字