diff --git a/include/base.h b/include/base.h index 6d3eeaf..24b7329 100644 --- a/include/base.h +++ b/include/base.h @@ -68,6 +68,7 @@ static inline char *read_file(char *filename) filesize = lseek(fd, 0, SEEK_END) + 1 ; contents = g_malloc(filesize * sizeof(char)); + assert (contents); lseek(fd, 0, SEEK_SET); read(fd,contents,filesize); diff --git a/include/graphics.h b/include/graphics.h index 0686350..a066de8 100644 --- a/include/graphics.h +++ b/include/graphics.h @@ -24,6 +24,7 @@ */ #pragma once +#include "base.h" #include #include #include @@ -223,6 +224,7 @@ static inline GLuint create_shader(int type, const char *src) glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &log_len); buffer = g_malloc(log_len + 1); + assert (buffer); glGetShaderInfoLog(shader, log_len, NULL, buffer); g_warning("Compile failure in %s shader:\n%s", diff --git a/src/graphics/graphics.c b/src/graphics/graphics.c index 813b8e9..5077374 100644 --- a/src/graphics/graphics.c +++ b/src/graphics/graphics.c @@ -222,7 +222,7 @@ void graphics_write_vertex (GLfloat x, GLfloat y, GLfloat z) buffer_vertex_size += 3; - printf("Created vertex (%f,%f,%f), size is %d\n", x,y,z, buffer_vertex_size); + //printf("Created vertex (%f,%f,%f), size is %d\n", x,y,z, buffer_vertex_size); } /* @@ -293,7 +293,7 @@ void graphics_init_buffers(const void *gl_area) // colors glGenBuffers(1, &color_buffer); glBindBuffer(GL_ARRAY_BUFFER, color_buffer); - glBufferData(GL_ARRAY_BUFFER, buffer_colors_size * sizeof(buffer_colors_origin), buffer_colors_origin, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, buffer_colors_size * sizeof(buffer_colors_origin[0]), buffer_colors_origin, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); // We only use one VAO, so we always keep it bound @@ -377,6 +377,7 @@ bool graphics_init_shaders(const void *gl_area) glGetProgramiv(program, GL_INFO_LOG_LENGTH, &log_len); buffer = g_malloc(log_len + 1); + assert(buffer); glGetProgramInfoLog(program, log_len, NULL, buffer); g_warning("Linking failure:\n%s", buffer); @@ -573,12 +574,14 @@ bool graphics_init(const char *gl_area) // If it does not exist, allocs it if (gl_area_array == NULL) { gl_area_array = g_malloc0(sizeof(struct gl_area_entry *) * 2); + assert(gl_area_array); // If it does exist, g_reallocs it } else { gl_area_array = g_realloc(gl_area_array, (array_size + 1) * sizeof(struct gl_area_entry *)); + assert (gl_area_array); if (gl_area_array == NULL) { perror("Not enough memory to allocate gl_area_array"); return false; @@ -590,6 +593,7 @@ bool graphics_init(const char *gl_area) // Alloc new entry gl_area_array[array_size] = g_malloc0(sizeof(struct gl_area_entry)); + assert(gl_area_array[array_size]); strcpy(gl_area_array[array_size]->name, gl_area); @@ -633,6 +637,7 @@ bool graphics_shutdown(const void *gl_area) gl_area_array = g_realloc(gl_area_array, (gl_area_size()) * sizeof(struct gl_area_entry *)); + assert (gl_area_array || !gl_area_size()); g_free(buffer_vertex_origin); g_free(buffer_colors_origin); @@ -716,6 +721,7 @@ void main_test_graphics (void) arrows, model_arrows_nb, pref_show_grid); + printf("main_test_graphics [ok]\n"); }