我有一個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