我在其中一个课程中声明了struct
:
#pragma once
#include <GL\glew.h>
#include <GLFW\glfw3.h>
#include "glm\glm.hpp"
#include <string>
#include <vector>
class OpenGLView
{
public:
void run();
bool loadObjSimple(
std::string path,
std::vector<glm::vec3>& vertices,
std::vector<glm::vec3>& normals,
std::vector<unsigned int>& elements);
bool initializeAndSetupWindow(GLint windowWidth, GLint windowHeight, std::string windowTitle);
GLuint loadShaders(const char * vertex_file_path, const char * fragment_file_path);
void loadBunnyAsset();
struct Asset
{
GLuint shaderProgramID;
GLuint vertexArray;
GLuint vertexBuffer;
GLuint normalBuffer;
GLuint elementBuffer;
GLint elementsSize;
Asset()
{
shaderProgramID = -1;
vertexArray = -1;
GLuint vertexBuffer = -1;
GLuint normalBuffer = -1;
GLuint elementBuffer = -1;
GLint elementsSize = -1;
}
};
private:
Asset bunny;
GLFWwindow * window;
};
但是,当我尝试从bunny.shaderProgramID
内部设置loadShaders
时,程序会抛出错误说:
Access violation executing location 0x00000000.
这是我进入调试器时的样子:
感谢您的帮助 - 我假设我对struct
的理解是错误的。
另外,我想我可以在struct
定义之后声明兔子,例如
struct Asset
{
blah blah blah
} bunny;
我错了吗?
答案 0 :(得分:0)
您提供的代码没有任何不妥。
只需查看调试器中的this
指针,它指向NULL!这很糟糕,它表明你在对象指针上调用了一些指向任何东西的方法!
如果您在main
功能中使用指针,则应初始化它。在调用new OpenGLView
之前将其设置为run
。