View Full Version : Constructors and deconstructors

01-10-2012, 04:33 AM
Hey there, I am having this issue understanding how the data flow of opengl works, I couldn't find any information on google either. So again I am coming to the opengl forums.

This is a basic example of my code


class Shader {
GLuint id;
bool bCreated;

void create();



Shader() {
id = 0;
bCreated = false;

~Shader() {
if(id != 0)

void create() {
id = glCreateShader(GL_VERTEX_SHADER);
bCreated = true;

This just throws access violations at me in the deconstructor.
Am I misunderstanding c++ or... What could possibly be wrong with the deconstructor is my thought.

Also I store my vertices in a pointer array which i then upload to a vbo. When my deconstructor deletes this vertice array I get weird errors.

I might be revealing too little, but my question is basically what does opengl do to the data I provide it ?

01-10-2012, 05:40 AM
One thing that can happen, which is not the case of your code example, is having a destructor calling OpenGL functions when there is no OpenGL context yet.

For example, if the initialization fails for your application before you have an OpenGL context, and you have global objects, then these objects will have the destructor called automatically at exit(). If so, the pointers may not have been initialized, having a zero value.

01-10-2012, 07:11 AM
It is possible that initialisation of the object works fine but at destruction time there is no opengl context bound: maybe the window was first destroyed and your destructor is called after that.

01-11-2012, 01:23 AM
Thank you for your responses. It did turn out that my opengl context was not bound when the opengl objects were destroyed.