Delete TexBuffer ?

Hi,
Recently I made a simple OpenGL program that works.

Today, I decided to copy this code in another new project, in order to re-use it.

The surprise is that this same code is not working.


    // Create the VAOs used for the update and render passes
    glGenVertexArrays(2, update_vao);
    glGenVertexArrays(2, render_vao);

	// Two buffers for each of position and velocity
    glGenBuffers(2, position_buffer);

	// Setup Update VAO 1
	glBindVertexArray(update_vao[0]);
		glBindBuffer(GL_ARRAY_BUFFER, position_buffer[0]);
		glBufferData(GL_ARRAY_BUFFER, 2*positions.size() * sizeof(GL_FLOAT), positions.constData(), GL_DYNAMIC_COPY);
		glEnableVertexAttribArray(0);
		glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
	// Setup Update VAO 2
    glBindVertexArray(update_vao[1]);
		glBindBuffer(GL_ARRAY_BUFFER, position_buffer[1]);
		glBufferData(GL_ARRAY_BUFFER, 2*positions.size() * sizeof(GL_FLOAT), NULL, GL_DYNAMIC_COPY);
		glEnableVertexAttribArray(0);
		glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);

	// Setup Render VAOs
    for (int i = 0; i < 2; i++)
    {
        glBindVertexArray(render_vao[i]);
			glBindBuffer(GL_ARRAY_BUFFER, position_buffer[i]);
			glEnableVertexAttribArray(0);
			glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
        
			glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elem_array);
			glBufferData(GL_ELEMENT_ARRAY_BUFFER, elements.size() * sizeof(GL_FLOAT), elements.constData(), GL_STATIC_DRAW);
    }

	// Setup position and velocity TBOs
    glGenTextures(2, position_tbo);

    // Done with VAOs
    glBindVertexArray(0);

    // Set up TBOs
    for (int i = 0; i < 2; i++)
    {
        glBindTexture(GL_TEXTURE_BUFFER, position_tbo[i]);
        glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, position_buffer[i]);
    }

I am having exceptions regarding the glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, flock_position[i]) ? I really don’t understand why? Maybe it is because I did not clean up everything after my rendering was done.

Here is the content of the destructor of my class :


	glDeleteTextures(2,position_tbo);
	glDeleteVertexArrays(2,update_vao);
	glDeleteVertexArrays(2,render_vao);
	glDeleteBuffers(2,position_buffer);

I never heard of a glDeleteTexBuffer and in this case the buffer I am binding to the TexBuffer is position_buffer.

Right now, If I run the first program, it works,
If I run the copy of the first program I have an exception (for memory allocation).

You can have problems if you include OpenGL calls in constructors/destructors if the context is not current when they are called, see http://www.opengl.org/wiki/Common_Mistakes#The_Object_Oriented_Language_Problem

Sorry but it did not help.
I only have problems when doing this :

glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, position_buffer[i]);

UP
If you you can just tell me in which order I have to delete all what I have created it would be great.
So I have VAO, some Buffer Objects and 2 textures.
If I delete a VAO with Buffer bound into it , will they be deleted too ??

If I delete a VAO with Buffer bound into it , will they be deleted too ??

I don’t believe it is deleted until it is unbound.

Put a some glGetError calls in your code. This is always a good idea