Problem with passing uniform data

I’ve got a problem with passing down a uniform variable (or better a matrix).
When I call glUniformMatrix4fv(…) my program crashes.
I draw my object by using a vertex index array.

Here is a part of my program:

void initialize() {
     // create VBOs
    glGenBuffers(1, &vboVId);
    glBindBuffer(GL_ARRAY_BUFFER, vboVId);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
    glGenBuffers(1, &vboIId);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIId);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

	// create shaders
	shaderProgramId = glCreateProgram();
	glAttachShader(shaderProgramId, vertexShaderId);
	glAttachShader(shaderProgramId, fragmentShaderId);

    // map locations
	locVertices = glGetAttribLocation(shaderProgramId, "a_position");
	locMvpMatrix = glGetUniformLocation(shaderProgramId, "u_mvpMatrix");

	glVertexAttribPointer(locVertices, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);

void loop() {
	glUniformMatrix4fv(locMvpMatrix, 1, 0, (float*)&mvpMatrix); // <-- when commented, the program works

Is the correct shader bound when you call glUniformMatrix4fv?
Looking at your code you don’t do that.
Then again the code snippet is minimal and I can’t tell if you have only the 1 shader or many (which you are not showing us).
If you do have many, then there is a need to issue glUseProgram(shaderProgramId) during the render loop.

Also, check the windows pointer function definition for glUniformMatrix4fv - there might be something wrong there if you have never used this command before in all your previous OpenGL projects.

locMvpMatrix could be -1 if the uniform does not exist but even then and even if the shader program is not bound at that moment, GL would give you an error and ignore the call, it would not crash.

So either glUniformMatrix4fv is NULL (are you using an extension loader? check if that had errors) or the mvpMatrix can’t be treated as plain old data. Tried to upload a float[16] array just to check if that wouldn’t crash?

I found the problem. The loop function was called too early. That was all. The code seems to be fine.
Sorry and thank you!

But anyway:
What did you mean with “windows pointer function definition”?
Can you give me a keyword to search for on the internet?