unhandled exception

Hello.
I’m simply trying to draw 1 triangle with a mixed VBO like this:


glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);

static const GLfloat vrtClrB[] =
	{
	0.0f, 0.0f, 0.3f, 0.1f, 0.6f,
	0.5f, 0.0f, 0.3f, 0.6f, 0.1f,
	0.5f, 0.5f, 0.333f, 0.333f, 0.333f
	};

glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vrtClrB), vrtClrB, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (const void*)0); // 2D position
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (const void*)(2 * sizeof(GLfloat))); // color

after which I continuously call

glDrawArrays(GL_TRIANGLES, 0, 3);

I’m using MSVS 2013 and it throws an unhandled exception in nvoglv64.dll.
The shaders compile and link just fine.
I just can’t see what I’m missing.

You pass 0-based pointers in glVertexAttribPointer, but at that time no VBO is bound to GL_ARRAY_BUFFER, so the address is not the start of your VBO, but the start of CPU memory, which is usually not accessible. Unbind the VBO after the glVertexAttribPointer calls.

Thanks. It doesn’t show the exception but it doesn’t show anything on the screen either. I was expecting a triangle on the right half of the screen…
EDIT:
Just to rule out the shaders:
Vertex shader

#version 330 core

layout(location = 0) in vec2 position;
layout(location = 1) in vec3 colorV;
out vec3 colorF;

void main()
	{
	gl_Position.xy = position;
	gl_Position.z = 0.0;
	gl_Position.w = 1.0;

	colorF = colorV;
	}

Fragment shader

#version 330 core

in vec3 colorF;
out vec3 color;

void main()
	{
	color = colorF;
	}

Stride should be 5 * sizeof(GLfloat) for both glVertexAttribPointer calls - it is the number of bytes the GL has to jump to get from one vertex to the next, i.e. when interleaving attributes like you do here it is the combined size of all attributes for a single vertex.

Right! Each attribute starts once every 5 floats :doh:
Man, this is one of those times when no matter how many bugs you solve, you find one more and after solving it, the app implacably keeps being broken.
After the stride correction the screen is still black. By my calculations, even with the wrong stride, a triangle should be drawn on the screen.

Ok, after hours of checking and reading I discovered that the effing triangle was drawn there all along! It was a black tri on a black background. This I never expected since in the fragment shader I specified the color myself:

#version 330 core

out vec4 color;

void main()
	{
	color = vec4(1.0, 1.0, 1.0, 1.0);
	}

and not only this but I tried with different colors. I discovered by accident when I changed the clear color to green. No matter what the tri is black.

So what is the problem? Does somebody have a guess? Please?

EDIT:
I found the bug; seems that OpenGL doesn’t complain and it goes on working fine, if you create the shaders but you don’t create the program! I declared a GLuint for the program and used it as is without calling glCreateProgram().
Shaders compiled and linked just fine, vertex shader executed as expected but fragment shader didn’t.

This under no circumstances should be allowed!