shithub: libgraphics

Download patch

ref: 930e09a2ea12275cf2e04577a170a2be342db045
parent: 0aa5a5517703a7dcbcf0ef2ef29fa37f8f1da6ed
author: rodri <rgl@antares-labs.eu>
date: Wed Apr 3 11:43:46 EDT 2024

scene: implement full cleanup procedures.

--- a/graphics.h
+++ b/graphics.h
@@ -266,6 +266,7 @@
 void delentity(Entity*);
 Scene *newscene(char*);
 void delscene(Scene*);
+void clearscene(Scene*);
 
 /* vertex */
 void addvattr(Vertex*, char*, int, void*);
--- a/scene.c
+++ b/scene.c
@@ -117,6 +117,14 @@
 void
 delmodel(Model *m)
 {
+	if(m->obj != nil)
+		objfree(m->obj);
+	if(m->tex != nil)
+		freememimage(m->tex);
+	if(m->nor != nil)
+		freememimage(m->nor);
+	if(m->nelems > 0)
+		free(m->elems);
 	free(m);
 }
 
@@ -138,7 +146,7 @@
 void
 delentity(Entity *e)
 {
-	/* TODO free model */
+	delmodel(e->mdl);
 	free(e);
 }
 
@@ -168,7 +176,18 @@
 void
 delscene(Scene *s)
 {
-	/* TODO free ents */
+	clearscene(s);
 	free(s->name);
 	free(s);
+}
+
+void
+clearscene(Scene *s)
+{
+	Entity *e;
+
+	for(e = s->ents.next; e != &s->ents; e = e->next){
+		delentity(e);
+		s->nents--;
+	}
 }