opengl

Sample code from LearnOpenGL.com
Log | Files | Refs

commit 44a4379b1c8b1d6785d8d15455bea7277afdef29
parent be62803f07e44f72e881c172bcb3bfd1766ce519
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Wed, 28 Jun 2023 10:23:38 +0900

add allocation counters for debugging

Diffstat:
Mglm.c | 20++++++++++++++++++++
Mglm.h | 4++++
Mmain.c | 9+++++++++
3 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/glm.c b/glm.c @@ -6,6 +6,9 @@ #include "glm.h" #include "err.h" +static int numVec = 0; // number of vecs which are allocated and not freed. +static int numMat = 0; // number of mats which are allocated and not freed. + char * vecStr(char *s, vec *v) { @@ -28,6 +31,7 @@ vecMake(float *data, int size) v->data[i] = data[i]; } v->size = size; + numVec++; return v; } @@ -36,6 +40,13 @@ vecFree(vec *v) { free(v->data); free(v); + numVec--; +} + +int +vecCount(void) +{ + return numVec; } int @@ -127,6 +138,7 @@ matMake(float *data, int size) m->data[i] = data[i]; } m->size = size; + numMat++; return m; } @@ -139,6 +151,7 @@ matMakeIdent(int size) m->data[i + size*i] = 1; } m->size = size; + numMat++; return m; } @@ -147,6 +160,13 @@ matFree(mat *m) { free(m->data); free(m); + numMat--; +} + +int +matCount(void) +{ + return numMat; } mat * diff --git a/glm.h b/glm.h @@ -16,6 +16,8 @@ char *vecStr(char *s, vec *v); vec *vecMake(float *data, int size); // VecFree() frees v. void vecFree(vec* v); +// VecCount() returns the number of vecs allocated and not yes freed. +int vecCount(void); // VecEq() tests equality of v and w. int vecEq(vec *v, vec *w); // VecAdd() adds w to v. w is unchanged. Returns the address of v or NULL if @@ -29,6 +31,8 @@ char *matStr(char *s, mat *m); mat *matMake(float *data, int size); mat *matMakeIdent(int size); void matFree(mat *m); +int matCount(void); + mat *matCopy(const mat *m); float *matDataPtr(mat *m); diff --git a/main.c b/main.c @@ -224,5 +224,14 @@ main(void) glDeleteBuffers(1, &VBO); ShaderDelete(shader); glfwTerminate(); + + if (matCount() != 0) { + fprintf(stderr, "%d mats not freed\n", matCount()); + assert(0); + } + if (vecCount() != 0) { + fprintf(stderr, "%d mats not freed\n", vecCount()); + assert(0); + } return 0; }