2014-10-27 36 views
0

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

您需要告訴我們您是如何使用它的,包括如何實例化您嘗試使用的實例。 – 2014-10-27 03:35:05

+0

這個錯誤意味着你可能在嘗試訪問它的方法之前沒有實例化「兔子」。 – 2014-10-27 04:10:02

+0

我通過使用你的類代碼進行檢查,struct沒有錯,你需要檢查你的其他代碼。 – Raki 2014-10-27 05:32:36

回答

0

在您提供的代碼中沒有什麼不好的。

只要看看你的this指針在調試器中,它指向NULL!這很糟糕,它表明你在對象指針上調用一些指向沒有任何東西的方法!

如果在main函數中使用指針,則應對其進行初始化。將其設置爲new OpenGLView,然後致電run就可以了。

+0

事實證明,我只需要在創建窗口後加載我的着色器。 – LarrySellers 2014-10-27 23:33:40