better logging, less leaks i think

This commit is contained in:
amy 2023-04-18 19:28:29 -05:00
parent 11564889bb
commit 4930a32c44
5 changed files with 41 additions and 7 deletions

View File

@ -1,5 +1,5 @@
optimized build : `clang ./src/*.c -lm -lglfw -lGL -fno-trapping-math`
optimized build : `clang ./src/*.c -lm -lglfw -lGL -lGLEW -fno-trapping-math`
#known issues
- glfw causes memory leak (not lost, related to video drivers)
- glfw & glew causes memory leak (not lost, related to video drivers)

View File

@ -25,6 +25,7 @@ GLFWwindow* glfw_init(){
int w,h;
glfwGetFramebufferSize(window,&w,&h);
glViewport(0,0,w,h);
info("yay:D i made a window uwu");
return window;
/*
while(!glfwWindowShouldClose(window)){

View File

@ -265,8 +265,11 @@ point_arr* square_gen(double* tl, double* tr, double* bl, double*br){
join_cords(a,c);
join_cords(a,d);
free(b->c);
free(b);
free(c->c);
free(c);
free(d->c);
free(d);
return a;
}
point_arr* cube_gen(double* tl, double* tr, double* bl, double*br,
@ -277,22 +280,29 @@ point_arr* cube_gen(double* tl, double* tr, double* bl, double*br,
double s;
join_cords(a,b);
free(b->c);
free(b);
point_arr* c = square_gen(tl2,tr2,tl,tr);
join_cords(a,c);
free(c->c);
free(c);
point_arr* d = square_gen(bl2,br2,bl,br);
join_cords(a,d);
free(d->c);
free(d->c);
free(d);
point_arr* e = square_gen(tl,tl2,bl,bl2);
join_cords(a,e);
free(e->c);
free(e->c);
free(e);
point_arr* f = square_gen(br2,br,tr2,tr);
join_cords(a,f);
free(f->c);
free(f->c);
free(f);
return a;
}
int main(){
int main(int argc,char*argv[]){
flag_handle(argc,argv);
atexit(sig_handle);
GLFWwindow* w = glfw_init();
refresh_size(w);
GLenum err = glewInit();
@ -304,6 +314,7 @@ int main(){
GLuint fid = fshader_comp(fshader_src);
prog = build_shader(vid,fid);
glUseProgram(prog);
info("built shaders");
double tl2[3] = {5.0,200.0,400.0};
double tr2[3] = {200.0,200.0,400.0};
double bl2[3] = {5.0,5.0,200.0};
@ -401,8 +412,13 @@ int main(){
if(glfwWindowShouldClose(w))break;
}
free(a->c);
free(a->c);
free(a);
glfwDestroyWindow(w);
win_clean();
glDeleteShader(vid);
glDeleteShader(fid);
glDeleteShader(prog);
info("killed window:p");
return 0;
}

View File

@ -2,6 +2,15 @@
#include <stdlib.h>
#include "util.h"
#include "strings.h"
double allocs = 0;
//#define malloc(X) mmalloc(X);
void mmalloc(){
allocs++;
}
//#define free(X) ffree(X);
void ffree(){
allocs--;
}
int log_level = 0;
int __signal = 0;
void pexit(int s){
@ -9,6 +18,10 @@ void pexit(int s){
exit(s);
}
void sig_handle(void){
if(allocs>0)
warn("uneven allocations, memory leak(s)");
if(allocs==0)
info("even allocations, no internal leaks");
if(__signal==0){
printf("\x1b[90mexited with \x1b[32m\x1b[1msignal [ %i ] \x1b[0m\x1b[90mgraceful exit\x1b[0m\n",__signal);
} else if(__signal>0){

View File

@ -6,6 +6,10 @@
#include "string.h"
#define greater(a,b) (a>b?a:b)
#define lesser(a,b) (a>b?b:a)
#define malloc(X) malloc(X); mmalloc();
void mmalloc();
#define free(X) free(X); ffree();
void ffree();
void err_m(char*,void (*)(int),char*,int);
void warn_m(char*,char*,int ,...);
void info_m(char*,char*,int ,...);