Program crashes on run

I think i have a good enough grasp on the theory of Opengl but what is supposed to be my first working program refuses to run.
I use both Code Blocks and Eclipse but while the program compiles on both just fine, it crashes on startup…
In Code Blocks i get the “Process terminated with status -1073741634” error message and i get a generic error message in Eclipse.
I’ve gone through my code meticulously but i can’t seem to find a mistake.

Here is my code :


#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>

#include <GL\glew.h>
#include <GLFW\glfw3.h>

#include <glm\glm.hpp>
#include <glm\gtc\matrix_transform.hpp>
#include <glm\gtc	ype_ptr.hpp>

using namespace glm;
using namespace std;

GLuint program, vShader, fShader, VAO, buffer;

GLfloat color[]= {  0.0f, 1.0f, 0.0f, 1.0f};
GLFWwindow* window;

static const GLfloat vertexcube[]= {
    -1.0f, -1.0f, 0.0f,
     1.0f, -1.0f, 0.0f,
    -1.0f,  1.0f, 0.0f,
     1.0f,  1.0f, 0.0f,
    -1.0f, -1.0f, 2.0f,
     1.0f, -1.0f, 2.0f,
    -1.0f,  1.0f, 2.0f,
     1.0f,  1.0f, 2.0f

static const char* vShaderSource = {
    "#version 330 core
    "layout (location = 0 ) in vec3 vertexcube;"
    "uniform mat4 MVPmatrix;"
    "uniform vec4 setColor;"
    "out vec4 fColor;"
    "void main()"
    "fColor = setColor;"
    "gl_Position = MVPmatrix * vec4( vertexcube.x, vertexcube.y, vertexcube.z, 1.0f);"

static const char* fShaderSource = {
    "version 330 core
    "in vec4 fColor;"
   // "out vec4 color;"
    "void main()"
    "color = fColor;"
void errorHandling(GLuint shader) {
	GLint status;
	glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
	if (status == GL_FALSE) {
		GLint infoLogLength;
		glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);

		GLchar* strInfoLog = new GLchar[infoLogLength + 1];
		glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);

		cerr << "Compilation error in shader: " << strInfoLog ;
		delete[] strInfoLog;

void init() {

    program = glCreateProgram();

    vShader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource( vShader, 1, &vShaderSource , NULL);
    glCompileShader( vShader );

    fShader = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource ( fShader, 1, &fShaderSource, NULL );
    glCompileShader( fShader );

    glAttachShader(program, vShader);
    glAttachShader(program, fShader);


    GLint colorLoc;
    glm::vec4 color(1.0f, 0.0f, 0.0f, 1.0f);
    colorLoc = glGetUniformLocation(program, "setColor");
    glUniform4fv(colorLoc, 4, glm::value_ptr(color));

    glGenBuffers( 1 , &buffer);
    glBindBuffer( GL_ARRAY_BUFFER, buffer);
    glBufferData( GL_ARRAY_BUFFER, sizeof(vertexcube), vertexcube, GL_STATIC_DRAW  );

    glGenVertexArrays( 1, &VAO);
    glBindVertexArray( VAO );
    glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, ( void* ) 0 );


void render() {
    glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

    glm::vec3 cameraPos =           glm::vec3( 0.0f, -3.0f, 0.0f );
    glm::vec3 cameraTarget =        glm::vec3( 0.0f,  0.0f, 0.0f);
    glm::vec3 cameraDirection =     glm::normalize(cameraPos - cameraTarget);
    glm::vec3 cameraUp =            glm::vec3( 0.0f,  1.0f, 0.0f);

    glm::mat4 viewMatrix =          glm::lookAt(cameraPos, cameraTarget, cameraUp);
    glm::mat4 projectMatrix=        glm::frustum(-5.0f, 5.0f, 5.0f, -5.0f, -5.0f, 5.0f);

    glm::mat4 modelMatrix  =      glm::mat4(1.0f);
    glm::rotate(modelMatrix, 1.f, glm::vec3(1.0f, 0.0f, 0.0f));

    glm::mat4 MVP  =  modelMatrix * viewMatrix * projectMatrix;
    glm::vec4 color( 1.0f, 0.0f, 0.0f, 1.0f);

    GLuint transLoc =	glGetUniformLocation(program, "MVPmatrix");
    glUniformMatrix4fv(transLoc, 1, GL_FALSE, glm::value_ptr(MVP));
    GLuint colorLoc = glGetUniformLocation(program, "setColor");
    glUniform4fv(colorLoc, 1,glm::value_ptr(color));

    glDrawArrays(GL_TRIANGLES, 0, 3);


int main( void ) {

    if (!glfwInit()){
        fprintf( stderr, "Failed to initialize GLEW

    glfwWindowHint  (       GL_SAMPLES, 4);
    glfwWindowHint  (       GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint  (       GLFW_CONTEXT_VERSION_MINOR, 5);
    glfwWindowHint  (       GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

    window = glfwCreateWindow( 640, 480, "Rotating Cube", NULL, NULL);
    if( window == NULL ){
        fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.
" );
        return -1;

    glewExperimental = GL_TRUE;
    if (glewInit() != GLEW_OK ){
            fprintf( stderr, "Failed to initialize GLEW
            return -1;


    do {



    }while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
            glfwWindowShouldClose(window) == 0 );

    glDeleteBuffers( 1, &buffer);
    glDeleteVertexArrays(1, &VAO);

    return 0;


And what happens when ran within a debugger ?
Does it crash from the first line ? If not, from which line ?

I have never used the debugger but i think it crashes on line 135.
That’s the line with “glDrawArrays (GL_TRIANGLES, 0, 3);” on it.
It also gives the following error message:

No source available for “nvoglv32!DrvValidateVersion() at 0x6459ec3a”

No idea what is going wrong here…

I changed “glDrawArrays( GL_TRIANGLES, 0, 3);” to “glDrawArrays( GL_TRIANGLES, 0, 2);” and the error message went away…
I now have a new error message however :

cannot open output file RotatingCube.exe: Permission denied

my first suggestion would be:
put a “std::cin.get();” right before you call “init();”
then right after you call “init();” etc … you get the idea ?!

beside that, i suppose that you used a pointer wrong, like that in “glBufferData(…, …, sizeof(vertexcube), …)”
“vertexcube” is a pointer, and pointers have a size of 32bit / 64bit
if you use a c++ standard library container instead, like std::vector<> or std::array<>, you can eliminate that kind of problem

instead of:
sizeof(float) * vertexcube.size()