我有一个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;
我错了吗?
您需要告诉我们您是如何使用它的,包括如何实例化您尝试使用的实例。 – 2014-10-27 03:35:05
这个错误意味着你可能在尝试访问它的方法之前没有实例化“兔子”。 – 2014-10-27 04:10:02
我通过使用你的类代码进行检查,struct没有错,你需要检查你的其他代码。 – Raki 2014-10-27 05:32:36