Home Ask Login Register

Developers Planet

Your answer is one click away!

Helen February 2016

OpenGL: Debug assertion failed

#include <stdio.h>
#include <GL\glew.h>
#include <GL\freeglut.h>

#define BUFFER_OFFSET(i) ((char *)NULL+(i))
GLuint shaderProgramID;
GLuint vao = 0;
GLuint vbo;
GLuint positionID, colorID;

#pragma region SHADER_FUNCTIONS
static char* readFile(const char* fileName)
//Open the file
FILE* fp = fopen(fileName, "r");
//Move the file pointer to the end of the file and determining the length
fseek(fp, 0, SEEK_END);
long file_length = ftell(fp);
fseek(fp, 0, SEEK_SET);
char* contents = new char[file_length + 1];

//zero out memory
for (int i = 0; i < file_length + 1; i++)
    contents[i] = 0;

//Here's the actual read
fread(contents, 1, file_length, fp);
contents[file_length + 1] = '\0';
return contents;

bool compiledStatus(GLint shaderID){
GLint compiled = 0;
glGetShaderiv(shaderID, GL_COMPILE_STATUS, &compiled);
if (compiled) {
    return true;
else {
    GLint logLength;
    glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &logLength);
    char* msgBuffer = new char[logLength];
    glGetShaderInfoLog(shaderID, logLength, NULL, msgBuffer);
    printf("%s\n", msgBuffer);
    delete (msgBuffer);
    return false;

//Takes in source code as string
GLuint makeVertexShader(const char* shaderSource)
//Call GL to make a vertex shader and get the ID
GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER);

//Bind the provided source code to the shader ID
glShaderSource(vertexShaderID, 1, (const GLchar**)&shaderSource, NULL);

//Compile the vertex Shader

bool compiledCorrect = compiledStatus(vertexShaderID);
if (compiledCorrect)
    return vertexShaderID;
return -1;

return vertexShaderID;

GLuint makeFragmentShader(const char* shaderSource)
//Call GL to make a fragment shader and get the ID
GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
//Bind the provided source code to the shader ID
glShaderSource(fragmentShaderID, 1, (const GLchar**)&shaderSource,        


BDL February 2016

The breakpoint and the assertion already tell you most of it: It is not allowed to call fseek with a filepointer pointing to null since this indicates an invalid file.

I would guess that the path is wrong and thus the file cannot be opened. You should definitely add error handling and check whether fopen succeeds before issuing any file-access calls.

I'm not sure why you think that _CRT_SECURE_NO_WARNINGS could be related to the problem, since this definition supresses some warnings during compilation but does not change anything at runtime.

Post Status

Asked in February 2016
Viewed 3,585 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life