结构不存在

时间:2014-10-27 03:33:51

标签: c++ class opengl struct

我在其中一个课程中声明了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.

这是我进入调试器时的样子: debug screen

感谢您的帮助 - 我假设我对struct的理解是错误的。

另外,我想我可以在struct定义之后声明兔子,例如

struct Asset
{
 blah blah blah
} bunny;

我错了吗?

1 个答案:

答案 0 :(得分:0)

您提供的代码没有任何不妥。

只需查看调试器中的this指针,它指向NULL!这很糟糕,它表明你在对象指针上调用了一些指向任何东西的方法!

如果您在main功能中使用指针,则应初始化它。在调用new OpenGLView之前将其设置为run