The Use Of Class Pointer

Problem:

  A error occurred when I defined "NormalMapping normal"( used for manaing relative shader ) in my OpenGLApp class. The compiler return error message "access violation at location 00000000 ".

 

Analysis:

  The error message seems to indicate that I had invoked some gl-function before invoking glewInit. So I tried to find where I had behaved like that. Then I found that I have define " OpenGLApp app " before invoking glewInit function. And it automatically constructed object "normal" who automatically initialized shader in its constructor which need to invoke glLinkProgram and so on.

 

Solution:

  1.I recalled that the use of class pointer in others' code. So I replace the definition "NormalMap normal" by NormalMap* normal and add a statement "normal = new NormalMap()" after invoking glewInit. Then the program work fine.

  2.Anothe solution would be OK. Such as putting the definition of app after invoking glewInit.

 

Conclusion:

  When defining a class pointer,the object is not defined before the statement "pointer = new Class()". So the constructor would not be called when just define a class pointer. But if define a objec, the constructor is called automatically meanwhile. So it is better to use class pointer to avoid invoking some function before relative library initialized.

posted @ 2013-10-29 23:10  swdever  阅读(168)  评论(0)    收藏  举报